1 /****************************************************************************
2 * Copyright (c) 1998-2018,2019 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.519 2019/09/22 19:12:40 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;
84 #define NCURSES_CONST_PARAM char
86 #define mmask_t chtype /* not specified in XSI */
89 #ifdef CURSES_ACS_ARRAY
90 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
91 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
92 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
93 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
94 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
95 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
96 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
98 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
99 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
100 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
101 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
102 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
103 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
104 #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 */
123 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
124 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
125 #define reset_wchars(state) init_mb(state)
126 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
127 #define count_wchars(src, len, state) wcstombs(0, src, len)
128 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
129 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
134 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
135 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
136 #define reset_mbytes(state) init_mb(state)
137 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
138 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
139 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
140 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
144 #define ToggleAcs(temp,real) temp = ((temp == real) ? NULL : real)
146 #define P(string) printw("%s\n", string)
148 #define BLANK ' ' /* this is the background character */
150 static int MaxColors; /* the actual number of colors we'll use */
151 static int MinColors; /* the minimum color code */
152 static bool UseColors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
157 #if HAVE_COLOR_CONTENT
160 NCURSES_COLOR_T green;
161 NCURSES_COLOR_T blue;
164 static RGB_DATA *all_colors;
167 static void main_menu(bool);
168 static void failed(const char *s) GCC_NORETURN;
171 failed(const char *s)
175 ExitProgram(EXIT_FAILURE);
191 isQuit(int c, bool escape)
193 return ((c) == QUIT || (escape && ((c) == ESCAPE)));
195 #define case_QUIT QUIT: case ESCAPE
197 /* Common function to allow ^T to toggle trace-mode in the middle of a test
198 * so that trace-files can be made smaller.
201 wGetchar(WINDOW *win)
205 while ((c = wgetch(win)) == CTRL('T')) {
207 save_trace = _nc_tracing;
208 Trace(("TOGGLE-TRACING OFF"));
211 _nc_tracing = save_trace;
215 Trace(("TOGGLE-TRACING ON"));
222 #define Getchar() wGetchar(stdscr)
225 /* replaces wgetnstr(), since we want to be able to edit values */
227 wGetstring(WINDOW *win, char *buffer, int limit)
234 (void) wattrset(win, A_REVERSE);
236 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);
295 #if USE_WIDEC_SUPPORT
297 fullwidth_digit(int ch)
299 return (wchar_t) (ch + 0xff10 - '0');
303 make_fullwidth_text(wchar_t *target, const char *source)
306 while ((ch = *source++) != 0) {
307 *target++ = fullwidth_digit(ch);
313 make_narrow_text(wchar_t *target, const char *source)
316 while ((ch = *source++) != 0) {
317 *target++ = (wchar_t) ch;
324 make_fullwidth_digit(cchar_t *target, int digit)
328 source[0] = fullwidth_digit(digit + '0');
330 setcchar(target, source, A_NORMAL, 0, 0);
335 wGet_wchar(WINDOW *win, wint_t *result)
339 while ((c = wget_wch(win, result)) == CTRL('T')) {
341 save_trace = _nc_tracing;
342 Trace(("TOGGLE-TRACING OFF"));
345 _nc_tracing = save_trace;
349 Trace(("TOGGLE-TRACING ON"));
352 c = wget_wch(win, result);
356 #define Get_wchar(result) wGet_wchar(stdscr, result)
358 /* replaces wgetn_wstr(), since we want to be able to edit values */
361 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
370 (void) wattrset(win, A_REVERSE);
372 x = (int) wcslen(buffer);
374 if (x > (int) wcslen(buffer))
375 x = (int) wcslen(buffer);
377 /* clear the "window' */
379 wprintw(win, "%*s", limit, " ");
381 /* write the existing buffer contents */
383 waddnwstr(win, buffer, limit);
385 /* positions the cursor past character 'x' */
387 waddnwstr(win, buffer, x);
389 switch (wGet_wchar(win, &ch)) {
429 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
449 } else if ((int) wcslen(buffer) < limit) {
451 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
452 buffer[j] = buffer[j - 1];
454 buffer[x++] = (wchar_t) ch;
461 wattroff(win, A_REVERSE);
465 #endif /* USE_SOFTKEYS */
467 #endif /* USE_WIDEC_SUPPORT */
473 addstr("Press any key to continue... ");
478 Cannot(const char *what)
480 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
486 ShellOut(bool message)
489 addstr("Shelling out...");
495 IGNORE_RC(system("sh"));
498 addstr("returned from shellout.\n");
502 #ifdef NCURSES_MOUSE_VERSION
504 * This function is the same as _tracemouse(), but we cannot count on that
505 * being available in the non-debug library.
508 mouse_decode(MEVENT const *ep)
510 static char buf[80 + (5 * 10) + (32 * 15)];
512 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
513 "id %2d at (%2d, %2d, %d) state %4lx = {",
514 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
517 if ((ep->bstate & m)==m) { \
518 _nc_STRCAT(buf, s, sizeof(buf)); \
519 _nc_STRCAT(buf, ", ", sizeof(buf)); \
522 SHOW(BUTTON1_RELEASED, "release-1");
523 SHOW(BUTTON1_PRESSED, "press-1");
524 SHOW(BUTTON1_CLICKED, "click-1");
525 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
526 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
527 #if NCURSES_MOUSE_VERSION == 1
528 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
531 SHOW(BUTTON2_RELEASED, "release-2");
532 SHOW(BUTTON2_PRESSED, "press-2");
533 SHOW(BUTTON2_CLICKED, "click-2");
534 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
535 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
536 #if NCURSES_MOUSE_VERSION == 1
537 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
540 SHOW(BUTTON3_RELEASED, "release-3");
541 SHOW(BUTTON3_PRESSED, "press-3");
542 SHOW(BUTTON3_CLICKED, "click-3");
543 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
544 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
545 #if NCURSES_MOUSE_VERSION == 1
546 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
549 SHOW(BUTTON4_RELEASED, "release-4");
550 SHOW(BUTTON4_PRESSED, "press-4");
551 SHOW(BUTTON4_CLICKED, "click-4");
552 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
553 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
554 #if NCURSES_MOUSE_VERSION == 1
555 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
558 #if NCURSES_MOUSE_VERSION == 2
559 SHOW(BUTTON5_RELEASED, "release-5");
560 SHOW(BUTTON5_PRESSED, "press-5");
561 SHOW(BUTTON5_CLICKED, "click-5");
562 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
563 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
566 SHOW(BUTTON_CTRL, "ctrl");
567 SHOW(BUTTON_SHIFT, "shift");
568 SHOW(BUTTON_ALT, "alt");
569 SHOW(ALL_MOUSE_EVENTS, "all-events");
570 SHOW(REPORT_MOUSE_POSITION, "position");
574 if (buf[strlen(buf) - 1] == ' ')
575 buf[strlen(buf) - 2] = '\0';
576 _nc_STRCAT(buf, "}", sizeof(buf));
581 show_mouse(WINDOW *win)
588 outside = !wenclose(win, event.y, event.x);
591 (void) wstandout(win);
592 waddstr(win, "KEY_MOUSE");
593 (void) wstandend(win);
595 waddstr(win, "KEY_MOUSE");
597 wprintw(win, ", %s", mouse_decode(&event));
602 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
607 wmove(win, event.y, event.x);
615 #endif /* NCURSES_MOUSE_VERSION */
617 /****************************************************************************
619 * Character input test
621 ****************************************************************************/
623 #define NUM_GETCH_FLAGS 256
624 typedef bool GetchFlags[NUM_GETCH_FLAGS];
627 setup_getch(WINDOW *win, GetchFlags flags)
629 keypad(win, flags['k']); /* should be redundant, but for testing */
630 meta(win, flags['m']); /* force this to a known state */
638 init_getch(WINDOW *win, GetchFlags flags, int delay)
640 memset(flags, FALSE, NUM_GETCH_FLAGS);
641 flags[UChar('k')] = (win == stdscr);
642 flags[UChar('m')] = TRUE;
643 flags[UChar('t')] = (delay != 0);
645 setup_getch(win, flags);
649 blocking_getch(GetchFlags flags, int delay)
651 return ((delay < 0) && flags['t']);
654 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
657 wgetch_help(WINDOW *win, GetchFlags flags)
659 static const char *help[] =
661 "e -- toggle echo mode"
662 ,"g -- triggers a getstr test"
663 ,"k -- toggle keypad/literal mode"
664 ,"m -- toggle meta (7-bit/8-bit) mode"
667 ,"t -- toggle timeout"
668 ,"w -- create a new window"
670 ,"z -- suspend this process"
674 unsigned chk = ((SIZEOF(help) + 1) / 2);
679 printw("Type any key to see its %s value. Also:\n",
680 flags['k'] ? "keypad" : "literal");
681 for (n = 0; n < SIZEOF(help); ++n) {
682 const char *msg = help[n];
683 int row = 1 + (int) (n % chk);
684 int col = (n >= chk) ? COLS / 2 : 0;
685 int flg = ((strstr(msg, "toggle") != 0)
686 && (flags[UChar(*msg)] != FALSE));
687 if (*msg == '^' && ExitOnEscape())
688 msg = "^[,^q -- quit";
691 MvPrintw(row, col, "%s", msg);
702 wgetch_wrap(WINDOW *win, int first_y)
704 int last_y = getmaxy(win) - 1;
705 int y = getcury(win) + 1;
713 #if defined(KEY_RESIZE) && HAVE_WRESIZE
719 static WINSTACK *winstack = 0;
720 static unsigned len_winstack = 0;
733 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
735 unsigned need = (level + 1) * 2;
737 assert(level < (unsigned) COLS);
741 winstack = typeMalloc(WINSTACK, len_winstack);
742 } else if (need >= len_winstack) {
744 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
747 failed("remember_boxes");
748 winstack[level].text = txt_win;
749 winstack[level].frame = box_win;
752 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
756 /* this chunk is now done in resize_term() */
763 #define slk_repaint() /* nothing */
766 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
768 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
769 * Resize both and paint the box in the parent.
772 resize_boxes(unsigned level, WINDOW *win)
776 int high = LINES - base;
780 wnoutrefresh(stdscr);
784 for (n = 0; n < level; ++n) {
785 wresize(winstack[n].frame, high, wide);
786 wresize(winstack[n].text, high - 2, wide - 2);
789 werase(winstack[n].text);
790 box(winstack[n].frame, 0, 0);
791 wnoutrefresh(winstack[n].frame);
792 wprintw(winstack[n].text,
794 getmaxy(winstack[n].text),
795 getmaxx(winstack[n].text));
796 wnoutrefresh(winstack[n].text);
797 if (winstack[n].text == win)
802 #endif /* resize_boxes */
804 #define forget_boxes() /* nothing */
805 #define remember_boxes(level,text,frame) /* nothing */
809 * Return-code is OK/ERR or a keyname.
814 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
818 wgetch_test(unsigned level, WINDOW *win, int delay)
821 int first_y, first_x;
825 init_getch(win, flags, delay);
826 notimeout(win, FALSE);
827 wtimeout(win, delay);
828 getyx(win, first_y, first_x);
830 wgetch_help(win, flags);
831 wsetscrreg(win, first_y, getmaxy(win) - 1);
837 while ((c = wGetchar(win)) == ERR) {
839 if (blocking_getch(flags, delay)) {
840 (void) wprintw(win, "%05d: input error", incount);
843 (void) wprintw(win, "%05d: input timed out", incount);
845 wgetch_wrap(win, first_y);
847 if (c == ERR && blocking_getch(flags, delay)) {
849 wgetch_wrap(win, first_y);
850 } else if (isQuit(c, ExitOnEscape())) {
852 } else if (c == 'e') {
853 flags[UChar('e')] = !flags[UChar('e')];
854 setup_getch(win, flags);
855 wgetch_help(win, flags);
856 } else if (c == 'g') {
857 waddstr(win, "getstr test: ");
859 c = wgetnstr(win, buf, sizeof(buf) - 1);
861 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
862 (int) strlen(buf), buf,
865 wgetch_wrap(win, first_y);
866 } else if (c == 'k') {
867 flags[UChar('k')] = !flags[UChar('k')];
868 setup_getch(win, flags);
869 wgetch_help(win, flags);
870 } else if (c == 'm') {
871 flags[UChar('m')] = !flags[UChar('m')];
872 setup_getch(win, flags);
873 wgetch_help(win, flags);
874 } else if (c == 's') {
876 } else if (c == 't') {
877 notimeout(win, flags[UChar('t')]);
878 flags[UChar('t')] = !flags[UChar('t')];
879 wgetch_help(win, flags);
880 } else if (c == 'w') {
881 int high = getmaxy(win) - 1 - first_y + 1;
882 int wide = getmaxx(win) - first_x;
884 int new_y = first_y + getbegy(win);
885 int new_x = first_x + getbegx(win);
887 getyx(win, old_y, old_x);
888 if (high > 2 && wide > 2) {
889 WINDOW *wb = newwin(high, wide, new_y, new_x);
890 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
895 remember_boxes(level, wi, wb);
896 wgetch_test(level + 1, wi, delay);
900 wgetch_help(win, flags);
901 wmove(win, old_y, old_x);
907 } else if (c == 'z') {
908 kill(getpid(), SIGTSTP);
911 wprintw(win, "Key pressed: %04o ", c);
912 #ifdef NCURSES_MOUSE_VERSION
913 if (c == KEY_MOUSE) {
916 #endif /* NCURSES_MOUSE_VERSION */
918 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
919 if (c == KEY_RESIZE) {
920 resize_boxes(level, win);
923 (void) waddstr(win, keyname(c));
924 } else if (c >= 0x80) {
925 unsigned c2 = (unsigned) c;
926 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
927 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
931 (void) wprintw(win, "%c", UChar(c));
932 else if (c2 != UChar(c))
933 (void) wprintw(win, "M-%s", unctrl(c2));
935 (void) wprintw(win, "%s", unctrl(c2));
936 waddstr(win, " (high-half character)");
939 (void) wprintw(win, "%c (ASCII printable character)", c);
941 (void) wprintw(win, "%s (ASCII control character)",
944 wgetch_wrap(win, first_y);
951 init_getch(win, flags, delay);
955 begin_getch_test(void)
962 #ifdef NCURSES_MOUSE_VERSION
963 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
966 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
968 getnstr(buf, sizeof(buf) - 1);
972 if (isdigit(UChar(buf[0]))) {
973 delay = atoi(buf) * 100;
983 finish_getch_test(void)
985 #ifdef NCURSES_MOUSE_VERSION
986 mousemask(0, (mmask_t *) 0);
995 getch_test(bool recur GCC_UNUSED)
997 int delay = begin_getch_test();
1000 wgetch_test(0, stdscr, delay);
1002 finish_getch_test();
1007 #if USE_WIDEC_SUPPORT
1009 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1010 * Resize both and paint the box in the parent.
1012 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1014 resize_wide_boxes(unsigned level, WINDOW *win)
1018 int high = LINES - base;
1022 wnoutrefresh(stdscr);
1026 for (n = 0; n < level; ++n) {
1027 wresize(winstack[n].frame, high, wide);
1028 wresize(winstack[n].text, high - 2, wide - 2);
1031 werase(winstack[n].text);
1032 box_set(winstack[n].frame, 0, 0);
1033 wnoutrefresh(winstack[n].frame);
1034 wprintw(winstack[n].text,
1036 getmaxy(winstack[n].text),
1037 getmaxx(winstack[n].text));
1038 wnoutrefresh(winstack[n].text);
1039 if (winstack[n].text == win)
1044 #endif /* KEY_RESIZE */
1047 wcstos(const wchar_t *src)
1051 const wchar_t *tmp = src;
1052 #ifndef state_unused
1056 reset_wchars(state);
1057 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1058 unsigned have = (unsigned) need;
1059 if ((result = typeCalloc(char, have + 1)) != 0) {
1061 if (trans_wchars(result, tmp, have, &state) != have) {
1073 wget_wch_test(unsigned level, WINDOW *win, int delay)
1075 wchar_t wchar_buf[BUFSIZ];
1076 wint_t wint_buf[BUFSIZ];
1077 int first_y, first_x;
1083 init_getch(win, flags, delay);
1084 notimeout(win, FALSE);
1085 wtimeout(win, delay);
1086 getyx(win, first_y, first_x);
1088 wgetch_help(win, flags);
1089 wsetscrreg(win, first_y, getmaxy(win) - 1);
1090 scrollok(win, TRUE);
1095 while ((code = wGet_wchar(win, &c)) == ERR) {
1097 if (blocking_getch(flags, delay)) {
1098 (void) wprintw(win, "%05d: input error", incount);
1101 (void) wprintw(win, "%05d: input timed out", incount);
1103 wgetch_wrap(win, first_y);
1105 if (code == ERR && blocking_getch(flags, delay)) {
1106 wprintw(win, "ERR");
1107 wgetch_wrap(win, first_y);
1108 } else if (isQuit((int) c, ExitOnEscape())) {
1110 } else if (c == 'e') {
1111 flags[UChar('e')] = !flags[UChar('e')];
1112 setup_getch(win, flags);
1113 wgetch_help(win, flags);
1114 } else if (c == 'g') {
1115 waddstr(win, "getstr test: ");
1117 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1120 wprintw(win, "wgetn_wstr returns an error.");
1123 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1126 if ((temp = wcstos(wchar_buf)) != 0) {
1127 wprintw(win, "I saw %d characters:\n\t`%s'.",
1128 (int) wcslen(wchar_buf), temp);
1131 wprintw(win, "I saw %d characters (cannot convert).",
1132 (int) wcslen(wchar_buf));
1136 wgetch_wrap(win, first_y);
1137 } else if (c == 'k') {
1138 flags[UChar('k')] = !flags[UChar('k')];
1139 setup_getch(win, flags);
1140 wgetch_help(win, flags);
1141 } else if (c == 'm') {
1142 flags[UChar('m')] = !flags[UChar('m')];
1143 setup_getch(win, flags);
1144 wgetch_help(win, flags);
1145 } else if (c == 's') {
1147 } else if (c == 't') {
1148 notimeout(win, flags[UChar('t')]);
1149 flags[UChar('t')] = !flags[UChar('t')];
1150 wgetch_help(win, flags);
1151 } else if (c == 'w') {
1152 int high = getmaxy(win) - 1 - first_y + 1;
1153 int wide = getmaxx(win) - first_x;
1155 int new_y = first_y + getbegy(win);
1156 int new_x = first_x + getbegx(win);
1158 getyx(win, old_y, old_x);
1159 if (high > 2 && wide > 2) {
1160 WINDOW *wb = newwin(high, wide, new_y, new_x);
1161 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1166 remember_boxes(level, wi, wb);
1167 wget_wch_test(level + 1, wi, delay);
1171 wgetch_help(win, flags);
1172 wmove(win, old_y, old_x);
1177 } else if (c == 'z') {
1178 kill(getpid(), SIGTSTP);
1181 wprintw(win, "Key pressed: %04o ", (int) c);
1182 #ifdef NCURSES_MOUSE_VERSION
1183 if (c == KEY_MOUSE) {
1186 #endif /* NCURSES_MOUSE_VERSION */
1187 if (code == KEY_CODE_YES) {
1188 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1189 if (c == KEY_RESIZE) {
1190 resize_wide_boxes(level, win);
1193 (void) waddstr(win, keyname((wchar_t) c));
1195 (void) waddstr(win, key_name((wchar_t) c));
1196 if (c < 256 && iscntrl(c)) {
1197 (void) wprintw(win, " (control character)");
1199 (void) wprintw(win, " = %#x (printable character)",
1203 wgetch_wrap(win, first_y);
1210 init_getch(win, flags, delay);
1214 x_getch_test(bool recur GCC_UNUSED)
1216 int delay = begin_getch_test();
1219 wget_wch_test(0, stdscr, delay);
1221 finish_getch_test();
1227 /****************************************************************************
1229 * Character attributes test
1231 ****************************************************************************/
1233 #if HAVE_SETUPTERM || HAVE_TGETENT
1234 #define get_ncv() TIGETNUM("ncv","NC")
1235 #define get_xmc() TIGETNUM("xmc","sg")
1237 #define get_ncv() -1
1238 #define get_xmc() -1
1245 static int first = TRUE;
1246 static chtype result = 0;
1252 char *area_pointer = parsed;
1254 tgetent(buffer, getenv("TERM"));
1257 if (TIGETSTR("smso", "so"))
1258 result |= A_STANDOUT;
1259 if (TIGETSTR("smul", "us"))
1260 result |= A_UNDERLINE;
1261 if (TIGETSTR("rev", "mr"))
1262 result |= A_REVERSE;
1263 if (TIGETSTR("blink", "mb"))
1265 if (TIGETSTR("dim", "mh"))
1267 if (TIGETSTR("bold", "md"))
1269 if (TIGETSTR("smacs", "ac"))
1270 result |= A_ALTCHARSET;
1276 #define termattrs() my_termattrs()
1279 #define ATTRSTRING_1ST 32 /* ' ' */
1280 #define ATTRSTRING_END 126 /* '~' */
1282 #define COLS_PRE_ATTRS 5
1283 #define COLS_AFT_ATTRS 15
1284 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1285 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1286 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1288 static char attr_test_string[MAX_ATTRSTRING + 1];
1291 attr_legend(WINDOW *helpwin)
1296 MvWPrintw(helpwin, row++, col,
1298 MvWPrintw(helpwin, row++, col,
1301 MvWPrintw(helpwin, row++, col,
1302 "Modify the test strings:");
1303 MvWPrintw(helpwin, row++, col,
1304 " A digit sets gaps on each side of displayed attributes");
1305 MvWPrintw(helpwin, row++, col,
1306 " </> shifts the text left/right. ");
1308 MvWPrintw(helpwin, row++, col,
1311 MvWPrintw(helpwin, row++, col,
1312 " f/F/b/B toggle foreground/background background color");
1313 MvWPrintw(helpwin, row++, col,
1314 " t/T toggle text/background color attribute");
1316 MvWPrintw(helpwin, row++, col,
1317 " a/A toggle ACS (alternate character set) mapping");
1318 MvWPrintw(helpwin, row, col,
1319 " v/V toggle video attribute to combine with each line");
1320 #if USE_WIDEC_SUPPORT
1321 MvWPrintw(helpwin, row, col,
1322 " w/W toggle normal/wide (double-width) test-characters");
1327 show_color_attr(int fg, int bg, int tx)
1330 printw(" Colors (fg %d, bg %d", fg, bg);
1332 printw(", text %d", tx);
1338 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1345 *fg = (NCURSES_COLOR_T) (*fg + 1);
1348 *fg = (NCURSES_COLOR_T) (*fg - 1);
1351 *bg = (NCURSES_COLOR_T) (*bg + 1);
1354 *bg = (NCURSES_COLOR_T) (*bg - 1);
1357 *tx = (NCURSES_COLOR_T) (*tx + 1);
1360 *tx = (NCURSES_COLOR_T) (*tx - 1);
1368 *fg = (NCURSES_COLOR_T) MinColors;
1369 if (*fg < MinColors)
1370 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1372 *bg = (NCURSES_COLOR_T) MinColors;
1373 if (*bg < MinColors)
1374 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1378 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1387 adjust_attr_string(int adjust)
1389 char save = attr_test_string[0];
1390 int first = ((int) UChar(save)) + adjust;
1392 if (first >= ATTRSTRING_1ST) {
1395 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1396 if (k > ATTRSTRING_END)
1398 attr_test_string[j] = (char) k;
1399 if (((k + 1 - first) % 5) == 0) {
1400 if (++j >= MAX_ATTRSTRING)
1402 attr_test_string[j] = ' ';
1405 if ((LEN_ATTRSTRING - j) > 5) {
1406 attr_test_string[0] = save;
1407 adjust_attr_string(adjust - 1);
1409 while (j < MAX_ATTRSTRING)
1410 attr_test_string[j++] = ' ';
1411 attr_test_string[j] = '\0';
1417 * Prefer the right-end of the string for starting, since that maps to the
1418 * VT100 line-drawing.
1421 default_attr_string(void)
1423 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1424 result += (LEN_ATTRSTRING / 5);
1425 if (result < ATTRSTRING_1ST)
1426 result = ATTRSTRING_1ST;
1431 init_attr_string(void)
1433 attr_test_string[0] = (char) default_attr_string();
1434 adjust_attr_string(0);
1438 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1440 int ncv = get_ncv();
1441 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1444 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1445 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1446 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1448 printw("%*s", skip, " ");
1450 * Just for testing, write text using the alternate character set one
1451 * character at a time (to pass its rendition directly), and use the
1452 * string operation for the other attributes.
1456 if (attr & A_ALTCHARSET) {
1459 for (s = attr_test_string; *s != '\0'; ++s) {
1460 chtype ch = UChar(*s);
1461 (void) waddch(win, ch | attr);
1464 (void) wattrset(win, AttrArg(attr, 0));
1465 (void) waddstr(win, attr_test_string);
1466 (void) wattroff(win, (int) attr);
1469 printw("%*s", skip, " ");
1470 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1471 if (test != A_NORMAL) {
1472 if (!(termattrs() & test)) {
1475 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1476 static const chtype table[] =
1495 for (n = 0; n < SIZEOF(table); n++) {
1496 if ((table[n] & attr) != 0
1497 && ((1 << n) & ncv) != 0) {
1505 if ((termattrs() & test) != test) {
1515 NCURSES_CONST char *name;
1518 static const ATTR_TBL attrs_to_test[] = {
1519 { A_STANDOUT, "STANDOUT" },
1520 { A_REVERSE, "REVERSE" },
1522 { A_UNDERLINE, "UNDERLINE" },
1524 { A_BLINK, "BLINK" },
1525 { A_PROTECT, "PROTECT" },
1527 { A_INVIS, "INVISIBLE" },
1530 { A_ITALIC, "ITALIC" },
1532 { A_NORMAL, "NORMAL" },
1537 init_attr_list(ATTR_TBL * target, attr_t attrs)
1539 unsigned result = 0;
1542 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1543 attr_t test = attrs_to_test[n].attr;
1544 if (test == A_NORMAL || (test & attrs) != 0) {
1545 target[result++] = attrs_to_test[n];
1551 #if USE_WIDEC_SUPPORT
1554 NCURSES_CONST char *name;
1557 static const W_ATTR_TBL w_attrs_to_test[] = {
1558 { WA_STANDOUT, "STANDOUT" },
1559 { WA_REVERSE, "REVERSE" },
1560 { WA_BOLD, "BOLD" },
1561 { WA_UNDERLINE, "UNDERLINE" },
1563 { WA_BLINK, "BLINK" },
1564 { WA_PROTECT, "PROTECT" },
1566 { WA_INVIS, "INVISIBLE" },
1569 { WA_ITALIC, "ITALIC" },
1571 { WA_NORMAL, "NORMAL" },
1576 init_w_attr_list(W_ATTR_TBL * target, attr_t attrs)
1578 unsigned result = 0;
1581 for (n = 0; n < SIZEOF(w_attrs_to_test); ++n) {
1582 attr_t test = w_attrs_to_test[n].attr;
1583 if (test == WA_NORMAL || (test & attrs) != 0) {
1584 target[result++] = w_attrs_to_test[n];
1592 attr_getc(int *skip,
1593 NCURSES_COLOR_T *fg,
1594 NCURSES_COLOR_T *bg,
1595 NCURSES_COLOR_T *tx,
1608 if (ch < 256 && isdigit(ch)) {
1616 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1618 attr_legend(helpwin);
1641 adjust_attr_string(-1);
1644 adjust_attr_string(1);
1650 error = cycle_color_attr(ch, fg, bg, tx);
1659 attr_test(bool recur GCC_UNUSED)
1660 /* test text attributes */
1663 int skip = get_xmc();
1664 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1665 NCURSES_COLOR_T bg = COLOR_BLACK;
1666 NCURSES_COLOR_T tx = -1;
1668 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1669 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1670 unsigned my_size = init_attr_list(my_list, termattrs());
1675 for (j = 0; j < my_size; ++j) {
1676 my_wins[j] = subwin(stdscr,
1678 2 + (int) (2 * j), COL_ATTRSTRING);
1679 scrollok(my_wins[j], FALSE);
1685 n = skip; /* make it easy */
1691 chtype normal = A_NORMAL | BLANK;
1692 chtype extras = (chtype) ac;
1695 NCURSES_PAIRS_T pair = 0;
1696 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1698 if (init_pair(pair, fg, bg) == ERR) {
1701 normal |= (chtype) COLOR_PAIR(pair);
1706 if (init_pair(pair, tx, bg) == ERR) {
1709 extras |= (chtype) COLOR_PAIR(pair);
1719 MvAddStr(0, 20, "Character attribute test display");
1721 for (j = 0; j < my_size; ++j) {
1722 bool arrow = (j == k);
1723 row = show_attr(my_wins[j], row, n, arrow,
1731 MvPrintw(row, COLS_PRE_ATTRS,
1732 "This terminal does %shave the magic-cookie glitch",
1733 get_xmc() > -1 ? "" : "not ");
1734 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1735 show_color_attr(fg, bg, tx);
1736 printw(" ACS (%d)", ac != 0);
1739 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1741 bkgdset(A_NORMAL | BLANK);
1746 Cannot("does not support video attributes.");
1751 #if USE_WIDEC_SUPPORT
1752 static bool use_fullwidth;
1753 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1755 #define FULL_LO 0xff00
1756 #define FULL_HI 0xff5e
1757 #define HALF_LO 0x20
1759 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1760 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1761 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1764 * Returns an ASCII code in [32..126]
1767 normal_wchar(int ch)
1769 wchar_t result = (wchar_t) ch;
1770 if (isFullWidth(ch))
1771 result = ToNormalWidth(ch);
1776 * Returns either an ASCII code in in [32..126] or full-width in
1777 * [0xff00..0xff5e], according to use_fullwidth setting.
1780 target_wchar(int ch)
1782 wchar_t result = (wchar_t) ch;
1783 if (use_fullwidth) {
1784 if (!isFullWidth(ch))
1785 result = ToFullWidth(ch);
1787 if (isFullWidth(ch))
1788 result = ToNormalWidth(ch);
1794 wide_adjust_attr_string(int adjust)
1796 wchar_t save = wide_attr_test_string[0];
1797 int first = ((int) normal_wchar(save)) + adjust;
1799 if (first >= ATTRSTRING_1ST) {
1802 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1803 if (k > ATTRSTRING_END)
1805 wide_attr_test_string[j] = target_wchar(k);
1806 if (((k + 1 - first) % 5) == 0) {
1807 if (++j >= MAX_ATTRSTRING)
1809 wide_attr_test_string[j] = ' ';
1812 if ((LEN_ATTRSTRING - j) > 5) {
1813 wide_attr_test_string[0] = save;
1814 wide_adjust_attr_string(adjust - 1);
1816 while (j < MAX_ATTRSTRING)
1817 wide_attr_test_string[j++] = ' ';
1818 wide_attr_test_string[j] = '\0';
1824 wide_init_attr_string(void)
1826 use_fullwidth = FALSE;
1827 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1828 wide_adjust_attr_string(0);
1832 set_wide_background(NCURSES_PAIRS_T pair)
1839 setcchar(&normal, blank, A_NORMAL, pair, 0);
1845 get_wide_background(void)
1847 attr_t result = WA_NORMAL;
1850 NCURSES_PAIRS_T pair;
1852 memset(&ch, 0, sizeof(ch));
1853 if (getbkgrnd(&ch) != ERR) {
1854 wchar_t wch[CCHARW_MAX];
1856 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1864 wide_show_attr(WINDOW *win,
1869 NCURSES_PAIRS_T pair,
1872 int ncv = get_ncv();
1873 attr_t test = attr & ~WA_ALTCHARSET;
1876 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1877 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1878 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1880 printw("%*s", skip, " ");
1883 * Just for testing, write text using the alternate character set one
1884 * character at a time (to pass its rendition directly), and use the
1885 * string operation for the other attributes.
1889 if (attr & WA_ALTCHARSET) {
1893 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1897 setcchar(&ch, fill, attr, pair, 0);
1898 (void) wadd_wch(win, &ch);
1901 attr_t old_attr = 0;
1902 NCURSES_PAIRS_T old_pair = 0;
1904 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1905 (void) wattr_set(win, attr, pair, 0);
1906 (void) waddwstr(win, wide_attr_test_string);
1907 (void) wattr_set(win, old_attr, old_pair, 0);
1910 printw("%*s", skip, " ");
1911 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1912 if (test != A_NORMAL) {
1913 if (!(term_attrs() & test)) {
1916 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1917 static const attr_t table[] =
1931 for (n = 0; n < SIZEOF(table); n++) {
1932 if ((table[n] & attr) != 0
1933 && ((1 << n) & ncv) != 0) {
1941 if ((term_attrs() & test) != test) {
1950 wide_attr_getc(int *skip,
1951 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1952 NCURSES_COLOR_T *tx, int *ac,
1953 unsigned *kc, unsigned limit)
1963 if (ch < 256 && isdigit(ch)) {
1971 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1972 box_set(helpwin, 0, 0);
1973 attr_legend(helpwin);
1996 use_fullwidth = FALSE;
1997 wide_adjust_attr_string(0);
2000 use_fullwidth = TRUE;
2001 wide_adjust_attr_string(0);
2004 wide_adjust_attr_string(-1);
2007 wide_adjust_attr_string(1);
2013 error = cycle_color_attr(ch, fg, bg, tx);
2022 x_attr_test(bool recur GCC_UNUSED)
2023 /* test text attributes using wide-character calls */
2026 int skip = get_xmc();
2027 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
2028 NCURSES_COLOR_T bg = COLOR_BLACK;
2029 NCURSES_COLOR_T tx = -1;
2031 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
2032 WINDOW *my_wins[SIZEOF(w_attrs_to_test)];
2033 unsigned my_size = init_w_attr_list(my_list, term_attrs());
2038 for (j = 0; j < my_size; ++j) {
2039 my_wins[j] = subwin(stdscr,
2041 2 + (int) (2 * j), COL_ATTRSTRING);
2042 scrollok(my_wins[j], FALSE);
2048 n = skip; /* make it easy */
2050 wide_init_attr_string();
2054 NCURSES_PAIRS_T pair = 0;
2055 NCURSES_PAIRS_T extras = 0;
2058 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2061 if (init_pair(pair, fg, bg) == ERR) {
2068 if (init_pair(extras, tx, bg) == ERR) {
2073 set_wide_background(pair);
2076 box_set(stdscr, 0, 0);
2077 MvAddStr(0, 20, "Character attribute test display");
2079 for (j = 0; j < my_size; ++j) {
2080 row = wide_show_attr(my_wins[j], row, n, (j == k),
2088 MvPrintw(row, COLS_PRE_ATTRS,
2089 "This terminal does %shave the magic-cookie glitch",
2090 get_xmc() > -1 ? "" : "not ");
2091 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2092 show_color_attr(fg, bg, tx);
2093 printw(" ACS (%d)", ac != 0);
2096 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2098 set_wide_background(0);
2103 Cannot("does not support extended video attributes.");
2109 /****************************************************************************
2111 * Color support tests
2113 ****************************************************************************/
2115 static NCURSES_CONST char *the_color_names[] =
2136 show_color_name(int y, int x, int color, bool wide, int zoom)
2138 if (move(y, x) != ERR) {
2143 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2147 if ((int) strlen(temp) >= width) {
2149 while ((1 << pwr2) < color)
2151 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2152 width > 4 ? "2^%d" : "^%d", pwr2);
2154 } else if (color >= 8) {
2155 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2157 } else if (color < 0) {
2158 _nc_STRCPY(temp, "default", sizeof(temp));
2160 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2161 "%.*s", 16, the_color_names[color]);
2163 printw("%-*.*s", width, width, temp);
2168 color_legend(WINDOW *helpwin, bool wide)
2173 MvWPrintw(helpwin, row++, col,
2176 MvWPrintw(helpwin, row++, col,
2177 "Use up/down arrow to scroll through the display if it is");
2178 MvWPrintw(helpwin, row++, col,
2179 "longer than one screen. Control/N and Control/P can be used");
2180 MvWPrintw(helpwin, row++, col,
2181 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2182 MvWPrintw(helpwin, row++, col,
2183 "full screen; control/B and control/F can be used here.");
2185 MvWPrintw(helpwin, row++, col,
2187 MvWPrintw(helpwin, row++, col,
2188 " a/A toggle altcharset off/on");
2189 MvWPrintw(helpwin, row++, col,
2190 " b/B toggle bold off/on");
2192 MvWPrintw(helpwin, row++, col,
2193 " c/C cycle used-colors through 8,16,...,COLORS");
2195 MvWPrintw(helpwin, row++, col,
2196 " n/N toggle text/number on/off");
2197 MvWPrintw(helpwin, row++, col,
2198 " r/R toggle reverse on/off");
2199 MvWPrintw(helpwin, row++, col,
2200 " w/W switch width between 4/8 columns");
2201 MvWPrintw(helpwin, row++, col,
2202 " z/Z zoom out (or in)");
2203 #if USE_WIDEC_SUPPORT
2205 MvWPrintw(helpwin, row++, col,
2206 "Wide characters:");
2207 MvWPrintw(helpwin, row, col,
2208 " x/X toggle text between ASCII and wide-character");
2215 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2218 color_cycle(int current, int step)
2220 int result = current;
2226 if ((result * 2) > COLORS) {
2229 while ((result * 2) < current) {
2235 if (current >= COLORS) {
2240 if (result > COLORS)
2246 /* generate a color test pattern */
2248 color_test(bool recur GCC_UNUSED)
2253 int grid_top = top + 3;
2254 int page_size = (LINES - grid_top);
2256 int colors_max = COLORS;
2263 bool opt_acsc = FALSE;
2264 bool opt_bold = FALSE;
2265 bool opt_revs = FALSE;
2266 bool opt_nums = FALSE;
2267 bool opt_wide = FALSE;
2272 Cannot("does not support color.");
2276 numbered = typeCalloc(char, COLS + 1);
2277 done = ((COLS < 16) || (numbered == 0));
2280 * Because the number of colors is usually a power of two, we also use
2281 * a power of two for the number of colors shown per line (to be tidy).
2283 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2288 int zoom_size = (1 << opt_zoom);
2289 int colors_max1 = colors_max / zoom_size;
2290 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2292 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2293 if (colors_max2 <= COLOR_PAIRS) {
2294 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2295 if (pairs_max > limit)
2298 if (pairs_max > COLOR_PAIRS)
2299 pairs_max = COLOR_PAIRS;
2300 if (pairs_max < colors_max1)
2301 pairs_max = colors_max1;
2303 /* this assumes an 80-column line */
2307 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2311 per_row = (col_limit / width);
2313 per_row -= MinColors;
2315 row_limit = (pairs_max + per_row - 1) / per_row;
2318 (void) printw("There are %d color pairs and %d colors",
2320 if (colors_max1 != COLORS)
2321 (void) printw(" (using %d colors)", colors_max1);
2323 (void) addstr(" besides 'default'");
2325 (void) printw(" zoom:%d", opt_zoom);
2328 MvPrintw(top + 1, 0,
2329 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2332 opt_bold ? "on" : "off");
2334 /* show color names/numbers across the top */
2335 for (i = 0; i < per_row; i++) {
2336 show_color_name(top + 2,
2338 (int) i * zoom_size + MinColors,
2343 /* show a grid of colors, with color names/ numbers on the left */
2344 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2345 int row = grid_top + (i / per_row) - base_row;
2346 int col = (i % per_row + 1) * width;
2347 NCURSES_PAIRS_T pair = i;
2349 if ((i / per_row) > row_limit)
2352 #define InxToFG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) % (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2353 #define InxToBG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) / (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2354 if (row >= 0 && move(row, col) != ERR) {
2355 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) InxToFG(i);
2356 NCURSES_COLOR_T bg = (NCURSES_COLOR_T) InxToBG(i);
2358 init_pair(pair, fg, bg);
2359 attron(COLOR_PAIR(pair));
2361 attron(A_ALTCHARSET);
2368 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2372 printw("%-*.*s", width, width, hello);
2373 (void) attrset(A_NORMAL);
2375 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2376 show_color_name(row, 0,
2387 switch (wGetchar(stdscr)) {
2401 colors_max = color_cycle(colors_max, -1);
2404 colors_max = color_cycle(colors_max, 1);
2422 set_color_test(opt_wide, FALSE);
2425 set_color_test(opt_wide, TRUE);
2428 if (opt_zoom <= 0) {
2436 if ((1 << opt_zoom) >= colors_max) {
2445 if (base_row <= 0) {
2453 if (base_row + page_size >= row_limit) {
2462 if (base_row <= 0) {
2465 base_row -= (page_size - 1);
2473 if (base_row + page_size >= row_limit) {
2476 base_row += page_size - 1;
2477 if (base_row + page_size >= row_limit) {
2478 base_row = row_limit - page_size - 1;
2483 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2485 color_legend(helpwin, FALSE);
2503 #if USE_WIDEC_SUPPORT
2505 #if USE_EXTENDED_COLOR
2506 #define InitExtendedPair(p,f,g) init_extended_pair((p),(f),(g))
2507 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), &(p))
2508 #define EXTENDED_PAIRS_T int
2510 #define InitExtendedPair(p,f,g) init_pair((NCURSES_PAIRS_T) (p),(NCURSES_COLOR_T)(f),(NCURSES_COLOR_T)(g))
2511 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), NULL)
2512 #define EXTENDED_PAIRS_T NCURSES_PAIRS_T
2515 /* generate a color test pattern */
2517 x_color_test(bool recur GCC_UNUSED)
2522 int grid_top = top + 3;
2523 int page_size = (LINES - grid_top);
2525 int colors_max = COLORS;
2532 bool opt_acsc = FALSE;
2533 bool opt_bold = FALSE;
2534 bool opt_revs = FALSE;
2535 bool opt_wide = FALSE;
2536 bool opt_nums = FALSE;
2537 bool opt_xchr = FALSE;
2539 wchar_t *buffer = 0;
2543 Cannot("does not support color.");
2546 numbered = typeCalloc(char, COLS + 1);
2547 buffer = typeCalloc(wchar_t, COLS + 1);
2548 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2551 * Because the number of colors is usually a power of two, we also use
2552 * a power of two for the number of colors shown per line (to be tidy).
2554 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2559 int zoom_size = (1 << opt_zoom);
2560 int colors_max1 = colors_max / zoom_size;
2561 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2563 pairs_max = ((unsigned) (-1)) / 2;
2564 if (colors_max2 <= COLOR_PAIRS) {
2565 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2566 if (pairs_max > limit)
2569 if (pairs_max > COLOR_PAIRS)
2570 pairs_max = COLOR_PAIRS;
2571 if (pairs_max < colors_max1)
2572 pairs_max = colors_max1;
2577 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2581 per_row = (col_limit / width);
2583 per_row -= MinColors;
2586 make_fullwidth_text(buffer, hello);
2590 make_narrow_text(buffer, hello);
2593 row_limit = (pairs_max + per_row - 1) / per_row;
2596 (void) printw("There are %d color pairs and %d colors",
2598 if (colors_max1 != COLORS)
2599 (void) printw(" (using %d colors)", colors_max1);
2601 (void) addstr(" besides 'default'");
2603 (void) printw(" zoom:%d", opt_zoom);
2606 MvPrintw(top + 1, 0,
2607 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2610 opt_bold ? "on" : "off");
2612 /* show color names/numbers across the top */
2613 for (i = 0; i < per_row; i++) {
2614 show_color_name(top + 2,
2615 ((int) i + 1) * width,
2616 (int) i * zoom_size + MinColors,
2621 /* show a grid of colors, with color names/ numbers on the left */
2622 for (i = (base_row * per_row); i < pairs_max; i++) {
2623 int row = grid_top + ((int) i / per_row) - base_row;
2624 int col = ((int) i % per_row + 1) * width;
2627 if ((i / per_row) > row_limit)
2630 if (row >= 0 && move(row, col) != ERR) {
2631 InitExtendedPair(pair, InxToFG(i), InxToBG(i));
2632 (void) ExtendedColorSet(pair);
2634 attr_on(WA_ALTCHARSET, NULL);
2636 attr_on(WA_BOLD, NULL);
2638 attr_on(WA_REVERSE, NULL);
2641 _nc_SPRINTF(numbered,
2642 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2643 "{%02X}", (unsigned) i);
2645 make_fullwidth_text(buffer, numbered);
2647 make_narrow_text(buffer, numbered);
2650 addnwstr(buffer, width);
2651 (void) attr_set(A_NORMAL, 0, NULL);
2653 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2654 show_color_name(row, 0,
2665 switch (wGetchar(stdscr)) {
2679 colors_max = color_cycle(colors_max, -1);
2682 colors_max = color_cycle(colors_max, 1);
2700 set_color_test(opt_wide, FALSE);
2703 set_color_test(opt_wide, TRUE);
2712 if (opt_zoom <= 0) {
2720 if ((1 << opt_zoom) >= colors_max) {
2729 if (base_row <= 0) {
2737 if (base_row + page_size >= row_limit) {
2746 if (base_row <= 0) {
2749 base_row -= (page_size - 1);
2757 if (base_row + page_size >= row_limit) {
2760 base_row += page_size - 1;
2761 if (base_row + page_size >= row_limit) {
2762 base_row = row_limit - page_size - 1;
2767 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2769 color_legend(helpwin, TRUE);
2787 #endif /* USE_WIDEC_SUPPORT */
2789 #if HAVE_COLOR_CONTENT
2791 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2793 NCURSES_COLOR_T red, green, blue;
2795 color_content(current, &red, &green, &blue);
2799 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2802 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2805 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2809 if (init_color(current, red, green, blue) == ERR)
2814 reset_all_colors(void)
2818 for (c = 0; c < COLORS; ++c)
2821 all_colors[c].green,
2822 all_colors[c].blue);
2825 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2826 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2827 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2830 init_all_colors(bool xterm_colors, char *palette_file)
2833 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2835 failed("all_colors");
2836 for (cp = 0; cp < MaxColors; ++cp) {
2838 &all_colors[cp].red,
2839 &all_colors[cp].green,
2840 &all_colors[cp].blue);
2842 /* xterm and compatible terminals can read results of an OSC string
2843 * asking for the current color palette.
2847 char result[BUFSIZ];
2849 unsigned check_r, check_g, check_b;
2854 for (n = 0; n < MaxColors; ++n) {
2857 fprintf(stderr, "\033]4;%d;?\007", n);
2858 got = (int) read(0, result, sizeof(result) - 1);
2862 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2868 all_colors[n].red = DecodeRGB(check_r);
2869 all_colors[n].green = DecodeRGB(check_g);
2870 all_colors[n].blue = DecodeRGB(check_b);
2877 if (palette_file != 0) {
2878 FILE *fp = fopen(palette_file, "r");
2880 char buffer[BUFSIZ];
2881 int red, green, blue;
2884 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2885 if (sscanf(buffer, "scale:%d", &c) == 1) {
2887 } else if (sscanf(buffer, "%d:%d %d %d",
2896 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2897 all_colors[c].red = Scaled(red);
2898 all_colors[c].green = Scaled(green);
2899 all_colors[c].blue = Scaled(blue);
2907 #define scaled_rgb(n) ((255 * (n)) / 1000)
2910 color_edit(bool recur GCC_UNUSED)
2911 /* display the color test pattern, without trying to edit colors */
2915 int this_c, value, field;
2921 Cannot("does not support color.");
2923 } else if (!can_change_color()) {
2924 Cannot("has hardwired color values.");
2937 page_size = (LINES - 6);
2940 for (i = 0; i < MaxColors; i++)
2941 init_pair((NCURSES_PAIRS_T) i,
2942 (NCURSES_COLOR_T) COLOR_WHITE,
2943 (NCURSES_COLOR_T) i);
2945 MvPrintw(LINES - 2, 0, "Number: %d", value);
2948 NCURSES_COLOR_T red, green, blue;
2951 MvAddStr(0, 20, "Color RGB Value Editing");
2954 for (i = (NCURSES_COLOR_T) top_color;
2955 (i - top_color < page_size)
2956 && (i < MaxColors); i++) {
2959 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2960 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2961 (i == current ? '>' : ' '),
2962 (i < (int) SIZEOF(the_color_names)
2963 ? the_color_names[i] : numeric));
2964 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2966 (void) attrset(A_NORMAL);
2968 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2970 if (current == i && field == 0)
2972 printw("%04d", (int) red);
2973 if (current == i && field == 0)
2974 (void) attrset(A_NORMAL);
2976 if (current == i && field == 1)
2978 printw("%04d", (int) green);
2979 if (current == i && field == 1)
2980 (void) attrset(A_NORMAL);
2982 if (current == i && field == 2)
2984 printw("%04d", (int) blue);
2985 if (current == i && field == 2)
2986 (void) attrset(A_NORMAL);
2987 (void) attrset(A_NORMAL);
2988 printw(" ( %3d %3d %3d )",
2989 (int) scaled_rgb(red),
2990 (int) scaled_rgb(green),
2991 (int) scaled_rgb(blue));
2994 MvAddStr(LINES - 3, 0,
2995 "Use up/down to select a color, left/right to change fields.");
2996 MvAddStr(LINES - 2, 0,
2997 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2999 move(2 + current - top_color, 0);
3003 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
3025 current -= (page_size - 1);
3032 if (current < (MaxColors - 1))
3033 current += (page_size - 1);
3040 current = (current == 0 ? (MaxColors - 1) : current - 1);
3045 current = (current == (MaxColors - 1) ? 0 : current + 1);
3050 field = (field == 2 ? 0 : field + 1);
3055 field = (field == 0 ? 2 : field - 1);
3068 value = value * 10 + (this_c - '0');
3072 change_color((NCURSES_PAIRS_T) current, field, value, 1);
3076 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
3080 change_color((NCURSES_PAIRS_T) current, field, value, 0);
3085 P(" RGB Value Editing Help");
3087 P("You are in the RGB value editor. Use the arrow keys to select one of");
3088 P("the fields in one of the RGB triples of the current colors; the one");
3089 P("currently selected will be reverse-video highlighted.");
3091 P("To change a field, enter the digits of the new value; they are echoed");
3092 P("as entered. Finish by typing `='. The change will take effect instantly.");
3093 P("To increment or decrement a value, use the same procedure, but finish");
3094 P("with a `+' or `-'.");
3096 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3098 P("Press 'm' to invoke the top-level menu with the current color settings.");
3099 P("To quit, do ESC");
3108 for (i = 0; i < MaxColors; i++)
3109 init_pair((NCURSES_PAIRS_T) i,
3110 (NCURSES_COLOR_T) COLOR_WHITE,
3111 (NCURSES_COLOR_T) i);
3125 if (current >= MaxColors)
3126 current = MaxColors - 1;
3127 if (current < top_color)
3128 top_color = current;
3129 if (current - top_color >= page_size)
3130 top_color = current - (page_size - 1);
3132 MvPrintw(LINES - 1, 0, "Number: %d", value);
3135 (!isQuit(this_c, TRUE));
3140 * ncurses does not reset each color individually when calling endwin().
3147 #endif /* HAVE_COLOR_CONTENT */
3149 /****************************************************************************
3151 * Alternate character-set stuff
3153 ****************************************************************************/
3155 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3161 if ((*at_code += 1) >= limit)
3166 *at_code = limit - 1;
3175 *attr = list[*at_code].attr;
3179 #if USE_WIDEC_SUPPORT
3181 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3187 if ((*at_code += 1) >= limit)
3192 *at_code = limit - 1;
3201 *attr = list[*at_code].attr;
3207 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3209 bool result = FALSE;
3219 if ((*fg += 1) >= COLORS)
3227 if ((*bg += 1) >= COLORS)
3235 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3238 if (init_pair(*pair,
3239 (NCURSES_COLOR_T) *fg,
3240 (NCURSES_COLOR_T) *bg) == ERR) {
3249 /****************************************************************************
3251 * Soft-key label test
3253 ****************************************************************************/
3258 #define SLK_WORK (SLK_HELP + 3)
3263 static const char *table[] =
3265 "Available commands are:"
3267 ,"^L -- repaint this message and activate soft keys"
3268 ,"a/d -- activate/disable soft keys"
3269 ,"c -- set centered format for labels"
3270 ,"l -- set left-justified format for labels"
3271 ,"r -- set right-justified format for labels"
3272 ,"[12345678] -- set label; labels are numbered 1 through 8"
3273 ,"e -- erase stdscr (should not erase labels)"
3274 ,"s -- test scrolling of shortened screen"
3275 ,"v/V -- cycle through video attributes"
3277 ,"F/f/B/b -- cycle through foreground/background colors"
3279 ,"ESC -- return to main menu"
3281 ,"Note: if activating the soft keys causes your terminal to scroll up"
3282 ,"one line, your terminal auto-scrolls when anything is written to the"
3283 ,"last screen position. The ncurses code does not yet handle this"
3289 for (j = 0; j < SIZEOF(table); ++j) {
3297 call_slk_color(int fg, int bg)
3299 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3301 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3310 slk_test(bool recur GCC_UNUSED)
3311 /* exercise the soft keys */
3316 chtype attr = A_NORMAL;
3317 unsigned at_code = 0;
3319 int fg = COLOR_BLACK;
3320 int bg = COLOR_WHITE;
3321 NCURSES_PAIRS_T pair = 0;
3323 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3324 unsigned my_size = init_attr_list(my_list, termattrs());
3329 call_slk_color(fg, bg);
3339 MvAddStr(0, 20, "Soft Key Exerciser");
3354 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3355 while ((c = Getchar()) != 'Q' && (c != ERR))
3383 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3384 _nc_STRCPY(buf, "", sizeof(buf));
3385 if ((s = slk_label(c - '0')) != 0) {
3386 _nc_STRNCPY(buf, s, (size_t) 8);
3388 wGetstring(stdscr, buf, 8);
3389 slk_set((c - '0'), buf, fmt);
3398 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3400 wnoutrefresh(stdscr);
3405 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3412 if (cycle_colors(c, &fg, &bg, &pair)) {
3414 call_slk_color(fg, bg);
3424 } while (!isQuit(c = Getchar(), TRUE));
3433 #if USE_WIDEC_SUPPORT
3436 x_slk_test(bool recur GCC_UNUSED)
3437 /* exercise the soft keys */
3440 wchar_t buf[SLKLEN + 1];
3442 attr_t attr = WA_NORMAL;
3443 unsigned at_code = 0;
3444 int fg = COLOR_BLACK;
3445 int bg = COLOR_WHITE;
3446 NCURSES_PAIRS_T pair = 0;
3447 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3448 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3452 call_slk_color(fg, bg);
3459 attr_on(WA_BOLD, NULL);
3460 MvAddStr(0, 20, "Soft Key Exerciser");
3461 attr_off(WA_BOLD, NULL);
3475 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3476 while ((c = Getchar()) != 'Q' && (c != ERR))
3504 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3506 if ((s = slk_label(c - '0')) != 0) {
3507 char *temp = strdup(s);
3508 size_t used = strlen(temp);
3509 size_t want = SLKLEN;
3510 #ifndef state_unused
3515 while (want > 0 && used != 0) {
3517 const char *base = s;
3519 reset_mbytes(state);
3520 test = count_mbytes(base, 0, &state);
3521 if (test == (size_t) -1) {
3523 } else if (test > want) {
3526 reset_mbytes(state);
3527 trans_mbytes(buf, base, want, &state);
3533 wGet_wstring(stdscr, buf, SLKLEN);
3534 slk_wset((c - '0'), buf, fmt);
3545 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3546 call_slk_color(fg, bg);
3551 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3552 call_slk_color(fg, bg);
3555 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3557 wnoutrefresh(stdscr);
3561 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3562 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3568 if (cycle_colors(c, &fg, &bg, &pair)) {
3570 call_slk_color(fg, bg);
3580 } while (!isQuit(c = Getchar(), TRUE));
3589 #endif /* SLK_INIT */
3592 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3595 unsigned last = 255;
3601 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3606 for (code = first; code <= last; ++code) {
3607 int row = (int) (2 + (code / 16));
3608 int col = (int) (5 * (code % 16));
3609 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3610 for (count = 1; count < repeat; ++count) {
3611 AddCh(colored_chtype(code, attr, pair));
3618 * Show a slice of 32 characters, allowing those to be repeated up to the
3621 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3622 * terminal to perform functions. The remaining codes can be graphic.
3625 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3628 unsigned first = (unsigned) base;
3629 unsigned last = first + (unsigned) pagesize - 2;
3630 bool C1 = (first == 128);
3635 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3636 C1 ? "C1" : "GR", first, last);
3640 for (code = first; code <= last; code++) {
3642 int row = 2 + ((int) (code - first) % (pagesize / 2));
3643 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3645 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3646 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3650 nodelay(stdscr, TRUE);
3651 echochar(colored_chtype(code, attr, pair));
3653 /* (yes, this _is_ crude) */
3654 while ((reply = Getchar()) != ERR) {
3655 AddCh(UChar(reply));
3658 nodelay(stdscr, FALSE);
3660 } while (--count > 0);
3667 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3673 MvPrintw(0, 20, "Display of PC Character Codes");
3677 for (code = 0; code < 16; ++code) {
3678 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3680 for (code = 0; code < 256; code++) {
3682 int row = 3 + (int) (code / 16) + (code >= 128);
3683 int col = 8 + (int) (code % 16) * PC_COLS;
3684 if ((code % 16) == 0)
3685 MvPrintw(row, 0, "0x%02x:", code);
3696 * Skip the ones that do not work.
3700 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3703 } while (--count > 0);
3708 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3712 attr |= (attr_t) COLOR_PAIR(pair);
3716 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3721 colored_chtype(ACS_VLINE, attr, pair),
3722 colored_chtype(ACS_VLINE, attr, pair),
3723 colored_chtype(ACS_HLINE, attr, pair),
3724 colored_chtype(ACS_HLINE, attr, pair),
3725 colored_chtype(ACS_ULCORNER, attr, pair),
3726 colored_chtype(ACS_URCORNER, attr, pair),
3727 colored_chtype(ACS_LLCORNER, attr, pair),
3728 colored_chtype(ACS_LRCORNER, attr, pair));
3729 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3730 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3731 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3732 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3733 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3734 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3735 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3741 show_1_acs(int n, int repeat, const char *name, chtype code)
3743 const int height = 16;
3744 int row = 2 + (n % height);
3745 int col = (n / height) * COLS / 2;
3747 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3750 } while (--repeat > 0);
3755 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3756 /* display the ACS character set */
3760 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3764 MvAddStr(0, 20, "Display of the ACS Character Set");
3768 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3769 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3770 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3771 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3773 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3774 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3775 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3776 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3778 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3779 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3782 * HPUX's ACS definitions are broken here. Just give up.
3784 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3785 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3786 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3787 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3788 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3790 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3791 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3792 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3793 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3794 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3795 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3796 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3797 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3798 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3800 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3801 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3802 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3804 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3805 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3806 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3807 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3808 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3809 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3815 acs_test(bool recur GCC_UNUSED)
3819 char *term = getenv("TERM");
3820 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3823 chtype attr = A_NORMAL;
3826 int fg = COLOR_BLACK;
3827 int bg = COLOR_BLACK;
3828 unsigned at_code = 0;
3829 NCURSES_PAIRS_T pair = 0;
3830 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3831 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3832 unsigned my_size = init_attr_list(my_list, termattrs());
3840 ToggleAcs(last_show_acs, show_acs_chars);
3844 ToggleAcs(last_show_acs, show_pc_chars);
3849 if (pagesize == 32) {
3856 ToggleAcs(last_show_acs, show_box_chars);
3882 if (repeat < (COLS / 4))
3890 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3891 || cycle_colors(c, &fg, &bg, &pair)) {
3898 if (pagesize != 32) {
3899 show_256_chars(repeat, attr, pair);
3900 } else if (last_show_acs != 0) {
3901 last_show_acs(repeat, attr, pair);
3903 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3906 MvPrintw(LINES - 3, 0,
3907 "Note: ANSI terminals may not display C1 characters.");
3908 MvPrintw(LINES - 2, 0,
3909 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3912 MvPrintw(LINES - 1, 0,
3913 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3914 my_list[at_code].name,
3917 MvPrintw(LINES - 1, 0,
3918 "v/V cycles through video attributes (%s).",
3919 my_list[at_code].name);
3922 } while (!isQuit(c = Getchar(), TRUE));
3930 #if USE_WIDEC_SUPPORT
3932 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3938 TEST_CCHAR(src, count, {
3939 attr |= (test_attrs & A_ALTCHARSET);
3940 setcchar(dst, test_wch, attr, pair, NULL);
3949 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3950 * display. If there are no repeats, we could normally display 16 lines of 64
3951 * characters (1024 total). However, taking repeats and double-width cells
3952 * into account, use 256 characters for the page.
3955 show_paged_widechars(unsigned base,
3960 NCURSES_PAIRS_T pair)
3962 unsigned first = base * pagesize;
3963 unsigned last = first + pagesize - 1;
3971 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3974 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
3975 int row = (2 + (int) (code - (wchar_t) first) / per_line);
3976 int col = 5 * ((int) code % per_line);
3979 memset(&codes, 0, sizeof(codes));
3981 setcchar(&temp, codes, attr, pair, 0);
3983 if (wcwidth(code) == 0 && code != 0) {
3984 AddCh((chtype) space |
3985 (A_REVERSE ^ attr) |
3986 (attr_t) COLOR_PAIR(pair));
3989 for (count = 1; count < repeat; ++count) {
3996 show_upper_widechars(unsigned first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
4000 unsigned last = first + 31;
4004 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
4007 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
4008 int row = 2 + ((int) (code - (wchar_t) first) % 16);
4009 int col = ((int) (code - (wchar_t) first) / 16) * COLS / 2;
4014 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
4015 "%3ld (0x%lx)", (long) code, (long) code);
4016 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
4018 memset(&codes, 0, sizeof(codes));
4020 setcchar(&temp, codes, attr, pair, 0);
4026 * Give non-spacing characters something to combine with. If we
4027 * don't, they'll bunch up in a heap on the space after the ":".
4028 * Mark them with reverse-video to make them simpler to find on
4031 if (wcwidth(code) == 0) {
4032 AddCh((chtype) space |
4033 (A_REVERSE ^ attr) |
4034 (attr_t) COLOR_PAIR(pair));
4037 * This uses echo_wchar(), for comparison with the normal 'f'
4038 * test (and to make a test-case for echo_wchar()). The screen
4039 * may flicker because the erase() at the top of the function
4040 * is met by the builtin refresh() in echo_wchar().
4044 * The repeat-count may make text wrap - avoid that.
4046 getyx(stdscr, y, x);
4048 if (x >= col + (COLS / 2) - 2)
4050 } while (--count > 0);
4055 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
4057 const int height = 16;
4058 int row = 2 + (n % height);
4059 int col = (n / height) * COLS / 2;
4061 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4062 while (--repeat >= 0) {
4068 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
4071 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4072 /* display the wide-ACS character set */
4078 /*#define BOTH2(name) #name, &(name) */
4079 #define BOTH2(name) #name, MERGE_ATTR(name)
4083 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4087 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
4088 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
4089 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
4090 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
4092 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
4093 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
4094 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
4095 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
4097 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4098 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4100 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4101 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4102 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4103 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4105 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4106 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4107 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4108 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4109 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4110 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4111 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4113 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4115 #ifdef CURSES_WACS_ARRAY
4116 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4117 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4118 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4120 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4121 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4122 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4123 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4124 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4125 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4131 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4132 /* display the wide-ACS character set */
4138 /*#define BOTH2(name) #name, &(name) */
4139 #define BOTH2(name) #name, MERGE_ATTR(name)
4143 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4147 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4148 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4149 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4150 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4152 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4153 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4154 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4155 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4157 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4158 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4160 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4161 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4162 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4163 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4165 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4166 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4167 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4168 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4169 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4170 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4171 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4172 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4173 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4175 #ifdef CURSES_WACS_ARRAY
4176 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4177 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4178 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4180 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4181 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4182 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4183 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4184 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4185 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4192 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4193 /* display the wide-ACS character set */
4199 /*#define BOTH2(name) #name, &(name) */
4200 #define BOTH2(name) #name, MERGE_ATTR(name)
4204 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4208 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4209 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4210 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4211 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4213 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4214 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4215 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4216 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4218 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4219 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4221 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4222 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4223 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4224 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4226 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4227 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4228 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4229 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4230 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4231 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4232 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4233 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4234 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4236 #ifdef CURSES_WACS_ARRAY
4237 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4238 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4239 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4241 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4242 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4243 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4244 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4245 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4246 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4253 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4256 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4263 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4268 MERGE_ATTR(0, WACS_VLINE),
4269 MERGE_ATTR(1, WACS_VLINE),
4270 MERGE_ATTR(2, WACS_HLINE),
4271 MERGE_ATTR(3, WACS_HLINE),
4272 MERGE_ATTR(4, WACS_ULCORNER),
4273 MERGE_ATTR(5, WACS_URCORNER),
4274 MERGE_ATTR(6, WACS_LLCORNER),
4275 MERGE_ATTR(7, WACS_LRCORNER));
4277 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4278 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4279 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4280 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4281 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4282 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4283 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4291 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4293 const int height = 16;
4294 int row = 2 + (n % height);
4295 int col = (n / height) * COLS / 2;
4298 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4299 (void) attr_set(attr, pair, 0);
4300 _nc_STRNCPY(temp, code, 20);
4302 (void) attr_set(A_NORMAL, 0, 0);
4306 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4309 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4316 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4320 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4321 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4322 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4323 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4325 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4326 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4327 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4328 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4330 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4331 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4333 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4334 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4335 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4336 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4338 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4339 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4340 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4341 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4342 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4343 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4344 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4345 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4346 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4347 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4348 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4349 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4351 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4352 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4353 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4354 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4355 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4356 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4361 /* display the wide-ACS character set */
4363 x_acs_test(bool recur GCC_UNUSED)
4369 unsigned pagesize = 32;
4370 attr_t attr = WA_NORMAL;
4371 int fg = COLOR_BLACK;
4372 int bg = COLOR_BLACK;
4373 unsigned at_code = 0;
4374 NCURSES_PAIRS_T pair = 0;
4375 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4376 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4377 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4379 bool pending_code = FALSE;
4388 ToggleAcs(last_show_wacs, show_wacs_chars);
4392 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4397 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4401 if (pagesize == 32) {
4408 ToggleAcs(last_show_wacs, show_wbox_chars);
4411 ToggleAcs(last_show_wacs, show_utf8_chars);
4414 pending_code = !pending_code;
4416 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4417 } else if (at_page[0] != '\0') {
4418 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%x", digit);
4422 if (pending_code && isxdigit(c)) {
4423 size_t len = strlen(at_page);
4424 if (len && at_page[0] == '0') {
4425 memmove(at_page, at_page + 1, len--);
4427 if (len < sizeof(at_page) - 1) {
4428 at_page[len++] = (char) c;
4429 at_page[len] = '\0';
4431 } else if (pending_code
4432 && (c == '\b' || c == KEY_BACKSPACE || c == KEY_DC)) {
4433 size_t len = strlen(at_page);
4435 at_page[--len] = '\0';
4436 } else if (c < 256 && isdigit(c)) {
4437 digit = (unsigned) (c - '0');
4439 } else if (c == '+') {
4441 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4443 } else if (c == '-' && digit > 0) {
4445 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x",
4448 } else if (c == '>' && repeat < (COLS / 4)) {
4450 } else if (c == '<' && repeat > 1) {
4452 } else if (c == '_') {
4453 space = (space == ' ') ? '_' : ' ';
4455 } else if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)
4456 || cycle_colors(c, &fg, &bg, &pair)) {
4457 if (last_show_wacs != 0)
4465 if (pagesize != 32) {
4466 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4467 } else if (last_show_wacs != 0) {
4468 last_show_wacs(repeat, attr, pair);
4470 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4473 MvPrintw(LINES - 4, 0,
4474 "Select: a/d/t WACS, w=%d/page, @",
4477 pending_code ? at_page : "page");
4478 addstr(", x=box, u UTF-8, ^L repaint");
4479 MvPrintw(LINES - 3, 2,
4480 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4482 MvPrintw(LINES - 2, 2,
4483 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4484 my_list[at_code].name,
4487 MvPrintw(LINES - 2, 2,
4488 "v/V cycles through video attributes (%s).",
4489 my_list[at_code].name);
4492 } while (!isQuit(c = Getchar(), TRUE));
4503 * Graphic-rendition test (adapted from vttest)
4506 sgr_attr_test(bool recur GCC_UNUSED)
4510 for (pass = 0; pass < 2; pass++) {
4511 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4513 /* Use non-default colors if possible to exercise bce a little */
4515 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4516 normal |= (chtype) COLOR_PAIR(1);
4520 MvPrintw(1, 20, "Graphic rendition test pattern:");
4522 MvPrintw(4, 1, "vanilla");
4524 #define set_sgr(mask) bkgdset((normal^(mask)));
4526 MvPrintw(4, 40, "bold");
4528 set_sgr(A_UNDERLINE);
4529 MvPrintw(6, 6, "underline");
4531 set_sgr(A_BOLD | A_UNDERLINE);
4532 MvPrintw(6, 45, "bold underline");
4535 MvPrintw(8, 1, "blink");
4537 set_sgr(A_BLINK | A_BOLD);
4538 MvPrintw(8, 40, "bold blink");
4540 set_sgr(A_UNDERLINE | A_BLINK);
4541 MvPrintw(10, 6, "underline blink");
4543 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4544 MvPrintw(10, 45, "bold underline blink");
4547 MvPrintw(12, 1, "negative");
4549 set_sgr(A_BOLD | A_REVERSE);
4550 MvPrintw(12, 40, "bold negative");
4552 set_sgr(A_UNDERLINE | A_REVERSE);
4553 MvPrintw(14, 6, "underline negative");
4555 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4556 MvPrintw(14, 45, "bold underline negative");
4558 set_sgr(A_BLINK | A_REVERSE);
4559 MvPrintw(16, 1, "blink negative");
4561 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4562 MvPrintw(16, 40, "bold blink negative");
4564 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4565 MvPrintw(18, 6, "underline blink negative");
4567 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4568 MvPrintw(18, 45, "bold underline blink negative");
4571 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4577 bkgdset(A_NORMAL | BLANK);
4583 /****************************************************************************
4585 * Windows and scrolling tester.
4587 ****************************************************************************/
4589 #define BOTLINES 4 /* number of line stolen from screen bottom */
4595 #define FRAME struct frame
4604 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4605 #if (NCURSES_VERSION_PATCH < 20070331)
4606 #define is_keypad(win) (win)->_use_keypad
4607 #define is_scrollok(win) (win)->_scroll
4610 #define is_keypad(win) FALSE
4611 #define is_scrollok(win) FALSE
4615 frame_win(FRAME * curp)
4617 return (curp != 0) ? curp->wind : stdscr;
4620 /* We need to know if these flags are actually set, so don't look in FRAME.
4621 * These names are known to work with SVr4 curses as well as ncurses. The
4622 * _use_keypad name does not work with Solaris 8.
4625 HaveKeypad(FRAME * curp)
4627 WINDOW *win = frame_win(curp);
4629 return is_keypad(win);
4633 HaveScroll(FRAME * curp)
4635 WINDOW *win = frame_win(curp);
4637 return is_scrollok(win);
4641 newwin_legend(FRAME * curp)
4643 #define DATA(num, name) { name, num }
4644 static const struct {
4648 DATA(0, "^C = create window"),
4649 DATA(0, "^N = next window"),
4650 DATA(0, "^P = previous window"),
4651 DATA(0, "^F = scroll forward"),
4652 DATA(0, "^B = scroll backward"),
4653 DATA(1, "^K = keypad(%s)"),
4654 DATA(2, "^S = scrollok(%s)"),
4655 DATA(0, "^W = save window"),
4656 DATA(0, "^R = restore window"),
4658 DATA(0, "^X = resize"),
4660 DATA(3, "^Q%s = exit")
4664 bool do_keypad = HaveKeypad(curp);
4665 bool do_scroll = HaveScroll(curp);
4670 for (n = 0; n < SIZEOF(legend); n++) {
4673 switch (legend[n].code) {
4675 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4678 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4679 legend[n].msg, do_keypad ? "yes" : "no");
4682 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4683 legend[n].msg, do_scroll ? "yes" : "no");
4686 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4687 legend[n].msg, do_keypad ? "/ESC" : "");
4690 x = getcurx(stdscr);
4691 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4698 transient(FRAME * curp, NCURSES_CONST char *msg)
4700 newwin_legend(curp);
4702 MvAddStr(LINES - 1, 0, msg);
4708 printw("%s characters are echoed, window should %sscroll.",
4709 HaveKeypad(curp) ? "Non-arrow" : "All other",
4710 HaveScroll(curp) ? "" : "not ");
4715 newwin_report(FRAME * curp)
4716 /* report on the cursor's current position, then restore it */
4718 WINDOW *win = frame_win(curp);
4722 transient(curp, (char *) 0);
4724 move(LINES - 1, COLS - 17);
4725 printw("Y = %2d X = %2d", y, x);
4733 selectcell(int uli, int ulj, int lri, int lrj)
4734 /* arrows keys move cursor, return location at current on non-arrow key */
4736 static pair res; /* result cell */
4737 int si = lri - uli + 1; /* depth of the select area */
4738 int sj = lrj - ulj + 1; /* width of the select area */
4739 int i = 0, j = 0; /* offsets into the select area */
4744 move(uli + i, ulj + j);
4745 newwin_report((FRAME *) 0);
4747 switch (Getchar()) {
4761 return ((pair *) 0);
4762 #ifdef NCURSES_MOUSE_VERSION
4768 if (event.y > uli && event.x > ulj) {
4789 outerbox(pair ul, pair lr, bool onoff)
4790 /* draw or erase a box *outside* the given pair of corners */
4792 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4793 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4794 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4795 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4796 move(ul.y - 1, ul.x);
4797 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4798 move(ul.y, ul.x - 1);
4799 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4800 move(lr.y + 1, ul.x);
4801 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4802 move(ul.y, lr.x + 1);
4803 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4808 /* Ask user for a window definition */
4815 addstr("Use arrows to move cursor, anything else to mark corner 1");
4817 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4818 return ((WINDOW *) 0);
4819 memcpy(&ul, tmp, sizeof(pair));
4820 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4823 addstr("Use arrows to move cursor, anything else to mark corner 2");
4825 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4827 return ((WINDOW *) 0);
4828 memcpy(&lr, tmp, sizeof(pair));
4830 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4832 outerbox(ul, lr, TRUE);
4844 newwin_move(FRAME * curp, int dy, int dx)
4846 WINDOW *win = frame_win(curp);
4850 getyx(win, cur_y, cur_x);
4851 getmaxyx(win, max_y, max_x);
4852 if ((cur_x += dx) < 0)
4854 else if (cur_x >= max_x)
4856 if ((cur_y += dy) < 0)
4858 else if (cur_y >= max_y)
4860 wmove(win, cur_y, cur_x);
4864 delete_framed(FRAME * fp, bool showit)
4869 fp->last->next = fp->next;
4870 fp->next->last = fp->last;
4878 np = (fp == fp->next) ? NULL : fp->next;
4885 scroll_test(bool recur GCC_UNUSED)
4886 /* Demonstrate windows */
4889 FRAME *current = (FRAME *) 0, *neww;
4891 #if HAVE_PUTWIN && HAVE_GETWIN
4895 #define DUMPFILE "screendump"
4897 #ifdef NCURSES_MOUSE_VERSION
4898 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4903 transient((FRAME *) 0, (char *) 0);
4906 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4907 failed("scroll_test");
4910 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4911 failed("scroll_test");
4916 if (current == 0) { /* First element, */
4917 neww->next = neww; /* so point it at itself */
4920 neww->next = current->next;
4921 neww->last = current;
4922 neww->last->next = neww;
4923 neww->next->last = neww;
4926 /* SVr4 curses sets the keypad on all newly-created windows to
4927 * false. Someone reported that PDCurses makes new windows inherit
4928 * this flag. Remove the following 'keypad()' call to test this
4930 keypad(current->wind, TRUE);
4931 current->do_keypad = HaveKeypad(current);
4932 current->do_scroll = HaveScroll(current);
4935 case CTRL('N'): /* go to next window */
4937 current = current->next;
4940 case CTRL('P'): /* go to previous window */
4942 current = current->last;
4945 case CTRL('F'): /* scroll current window forward */
4947 wscrl(frame_win(current), 1);
4950 case CTRL('B'): /* scroll current window backwards */
4952 wscrl(frame_win(current), -1);
4955 case CTRL('K'): /* toggle keypad mode for current */
4957 current->do_keypad = !current->do_keypad;
4958 keypad(current->wind, current->do_keypad);
4964 current->do_scroll = !current->do_scroll;
4965 scrollok(current->wind, current->do_scroll);
4969 #if HAVE_PUTWIN && HAVE_GETWIN
4970 case CTRL('W'): /* save and delete window */
4971 if ((current != 0) && (current == current->next)) {
4972 transient(current, "Will not save/delete ONLY window");
4974 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4975 transient(current, "Can't open screen dump file");
4977 int rc = putwin(frame_win(current), fp);
4981 current = delete_framed(current, TRUE);
4983 transient(current, "Can't write screen dump file");
4988 case CTRL('R'): /* restore window */
4989 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4990 transient(current, "Can't open screen dump file");
4992 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4994 neww->next = current ? current->next : 0;
4995 neww->last = current;
4996 if (neww->last != 0)
4997 neww->last->next = neww;
4998 if (neww->next != 0)
4999 neww->next->last = neww;
5001 neww->wind = getwin(fp);
5003 wrefresh(neww->wind);
5005 failed("scroll_test");
5013 case CTRL('X'): /* resize window */
5020 addstr("Use arrows to move cursor, anything else to mark new corner");
5023 getbegyx(current->wind, ul.y, ul.x);
5025 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
5026 if (tmp == (pair *) 0) {
5031 getmaxyx(current->wind, lr.y, lr.x);
5034 outerbox(ul, lr, FALSE);
5035 wnoutrefresh(stdscr);
5037 /* strictly cosmetic hack for the test */
5038 getmaxyx(current->wind, my, mx);
5039 if (my > tmp->y - ul.y) {
5040 getyx(current->wind, lr.y, lr.x);
5041 wmove(current->wind, tmp->y - ul.y + 1, 0);
5042 wclrtobot(current->wind);
5043 wmove(current->wind, lr.y, lr.x);
5045 if (mx > tmp->x - ul.x) {
5047 for (i = 0; i < my; i++) {
5048 wmove(current->wind, i, tmp->x - ul.x + 1);
5049 wclrtoeol(current->wind);
5052 wnoutrefresh(current->wind);
5054 memcpy(&lr, tmp, sizeof(pair));
5055 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
5057 getbegyx(current->wind, ul.y, ul.x);
5058 getmaxyx(current->wind, lr.y, lr.x);
5061 outerbox(ul, lr, TRUE);
5062 wnoutrefresh(stdscr);
5064 wnoutrefresh(current->wind);
5070 #endif /* HAVE_WRESIZE */
5073 newwin_move(current, -1, 0);
5076 newwin_move(current, 1, 0);
5079 newwin_move(current, 0, -1);
5082 newwin_move(current, 0, 1);
5090 getyx(frame_win(current), y, x);
5094 x = getmaxx(frame_win(current)) - 1;
5096 (void) mvwdelch(frame_win(current), y, x);
5106 waddch(current->wind, (chtype) c);
5111 newwin_report(current);
5112 usescr = frame_win(current);
5115 (!isQuit(c = wGetchar(usescr), TRUE)
5119 while (current != 0)
5120 current = delete_framed(current, FALSE);
5122 scrollok(stdscr, TRUE); /* reset to driver's default */
5123 #ifdef NCURSES_MOUSE_VERSION
5124 mousemask(0, (mmask_t *) 0);
5132 /****************************************************************************
5136 ****************************************************************************/
5139 static int nap_msec = 1;
5141 static NCURSES_CONST char *mod[] =
5151 /*+-------------------------------------------------------------------------
5153 --------------------------------------------------------------------------*/
5155 wait_a_while(int msec GCC_UNUSED)
5165 else if (msec > 1000)
5166 sleep((unsigned) msec / 1000);
5170 } /* end of wait_a_while */
5172 /*+-------------------------------------------------------------------------
5174 --------------------------------------------------------------------------*/
5176 saywhat(NCURSES_CONST char *text)
5178 wmove(stdscr, LINES - 1, 0);
5180 if (text != 0 && *text != '\0') {
5181 waddstr(stdscr, text);
5182 waddstr(stdscr, "; ");
5184 waddstr(stdscr, "press any key to continue");
5185 } /* end of saywhat */
5187 /*+-------------------------------------------------------------------------
5188 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
5189 --------------------------------------------------------------------------*/
5191 mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx)
5196 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
5197 if ((pan = new_panel(win)) == 0) {
5199 } else if (UseColors) {
5200 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) ((color == COLOR_BLUE)
5203 NCURSES_COLOR_T bg = color;
5205 init_pair(color, fg, bg);
5206 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
5208 wbkgdset(win, A_BOLD | ' ');
5212 } /* end of mkpanel */
5214 /*+-------------------------------------------------------------------------
5216 --------------------------------------------------------------------------*/
5220 WINDOW *win = panel_window(pan);
5223 } /* end of rmpanel */
5225 /*+-------------------------------------------------------------------------
5227 --------------------------------------------------------------------------*/
5233 } /* end of pflush */
5235 /*+-------------------------------------------------------------------------
5237 --------------------------------------------------------------------------*/
5239 init_panel(WINDOW *win)
5243 for (y = 0; y < LINES - 1; y++) {
5244 for (x = 0; x < COLS; x++)
5245 wprintw(win, "%d", (y + x) % 10);
5250 fill_panel(PANEL *pan)
5252 WINDOW *win = panel_window(pan);
5253 const char *userptr = (const char *) panel_userptr(pan);
5254 int num = (userptr && *userptr) ? userptr[1] : '?';
5258 wprintw(win, "-pan%c-", num);
5261 for (y = 2; y < getmaxy(win) - 1; y++) {
5262 for (x = 1; x < getmaxx(win) - 1; x++) {
5264 waddch(win, UChar(num));
5269 #if USE_WIDEC_SUPPORT
5271 init_wide_panel(WINDOW *win)
5276 for (digit = 0; digit < 10; ++digit)
5277 make_fullwidth_digit(&temp[digit], digit);
5281 getyx(stdscr, y, x);
5282 digit = (y + x / 2) % 10;
5283 } while (wadd_wch(win, &temp[digit]) != ERR);
5287 fill_wide_panel(PANEL *pan)
5289 WINDOW *win = panel_window(pan);
5290 const char *userptr = (const char *) panel_userptr(pan);
5291 int num = (userptr && *userptr) ? userptr[1] : '?';
5295 wprintw(win, "-pan%c-", num);
5298 for (y = 2; y < getmaxy(win) - 1; y++) {
5299 for (x = 1; x < getmaxx(win) - 1; x++) {
5301 waddch(win, UChar(num));
5307 #define MAX_PANELS 5
5310 canned_panel(PANEL *px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
5312 int which = cmd[1] - '0';
5317 hide_panel(px[which]);
5320 show_panel(px[which]);
5323 top_panel(px[which]);
5326 bottom_panel(px[which]);
5333 wait_a_while(nap_msec);
5337 demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
5341 PANEL *px[MAX_PANELS + 1];
5343 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5347 for (count = 0; count < 5; count++) {
5348 px[1] = mkpanel(COLOR_RED,
5353 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
5355 px[2] = mkpanel(COLOR_GREEN,
5360 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
5362 px[3] = mkpanel(COLOR_YELLOW,
5367 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
5369 px[4] = mkpanel(COLOR_BLUE,
5374 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
5376 px[5] = mkpanel(COLOR_MAGENTA,
5381 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
5393 wait_a_while(nap_msec);
5395 saywhat("h3 s1 s2 s4 s5");
5396 move_panel(px[1], 0, 0);
5403 wait_a_while(nap_msec);
5405 canned_panel(px, "s1");
5406 canned_panel(px, "s2");
5409 move_panel(px[2], LINES / 3 + 1, COLS / 8);
5411 wait_a_while(nap_msec);
5413 canned_panel(px, "s3");
5416 move_panel(px[3], LINES / 4 + 1, COLS / 15);
5418 wait_a_while(nap_msec);
5420 canned_panel(px, "b3");
5421 canned_panel(px, "s4");
5422 canned_panel(px, "s5");
5423 canned_panel(px, "t3");
5424 canned_panel(px, "t1");
5425 canned_panel(px, "t2");
5426 canned_panel(px, "t3");
5427 canned_panel(px, "t4");
5429 for (itmp = 0; itmp < 6; itmp++) {
5430 WINDOW *w4 = panel_window(px[4]);
5431 WINDOW *w5 = panel_window(px[5]);
5434 wmove(w4, LINES / 8, 1);
5435 waddstr(w4, mod[itmp]);
5436 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5437 wmove(w5, LINES / 6, 1);
5438 waddstr(w5, mod[itmp]);
5440 wait_a_while(nap_msec);
5443 wmove(w4, LINES / 6, 1);
5444 waddstr(w4, mod[itmp]);
5445 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
5446 wmove(w5, LINES / 8, 1);
5447 waddstr(w5, mod[itmp]);
5449 wait_a_while(nap_msec);
5453 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5455 wait_a_while(nap_msec);
5457 canned_panel(px, "t5");
5458 canned_panel(px, "t2");
5459 canned_panel(px, "t1");
5460 canned_panel(px, "d2");
5461 canned_panel(px, "h3");
5462 canned_panel(px, "d1");
5463 canned_panel(px, "d4");
5464 canned_panel(px, "d5");
5465 canned_panel(px, "d3");
5467 wait_a_while(nap_msec);
5480 panel_test(bool recur GCC_UNUSED)
5482 return demo_panels(init_panel, fill_panel);
5486 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
5488 x_panel_test(bool recur GCC_UNUSED)
5490 return demo_panels(init_wide_panel, fill_wide_panel);
5493 #endif /* USE_LIBPANEL */
5495 /****************************************************************************
5499 ****************************************************************************/
5503 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
5504 * though we can rely on negative x/y values to stop the macro.
5507 do_h_line(int y, int x, chtype c, int to)
5510 MvHLine(y, x, c, (to) - (x));
5514 do_v_line(int y, int x, chtype c, int to)
5517 MvVLine(y, x, c, (to) - (y));
5522 static bool pending_pan = FALSE;
5523 static bool show_panner_legend = TRUE;
5526 panner_legend(int line)
5528 static const char *const legend[] =
5530 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
5531 "Use +,- (or j,k) to grow/shrink the panner vertically.",
5532 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
5533 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
5535 int n = ((int) SIZEOF(legend) - (LINES - line));
5537 if (move(line, 0) != ERR) {
5538 if (show_panner_legend)
5539 printw("%s", legend[n]);
5541 return show_panner_legend;
5548 panner_h_cleanup(int from_y, int from_x, int to_x)
5550 if (!panner_legend(from_y))
5551 do_h_line(from_y, from_x, ' ', to_x);
5555 panner_v_cleanup(int from_y, int from_x, int to_y)
5557 if (!panner_legend(from_y))
5558 do_v_line(from_y, from_x, ' ', to_y);
5562 fill_pad(WINDOW *panpad, bool pan_lines, bool colored)
5565 unsigned gridcount = 0;
5569 fill = (chtype) COLOR_PAIR(1);
5572 wmove(panpad, 0, 0);
5573 for (y = 0; y < getmaxy(panpad); y++) {
5574 for (x = 0; x < getmaxx(panpad); x++) {
5575 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
5576 if (y == 0 && x == 0)
5577 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
5579 waddch(panpad, pan_lines ? ACS_TTEE : '+');
5580 else if (y == 0 || x == 0)
5581 waddch(panpad, pan_lines ? ACS_LTEE : '+');
5583 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
5584 (int) (gridcount++ % 26)) | fill);
5585 } else if (y % GRIDSIZE == 0)
5586 waddch(panpad, pan_lines ? ACS_HLINE : '-');
5587 else if (x % GRIDSIZE == 0)
5588 waddch(panpad, pan_lines ? ACS_VLINE : '|');
5590 waddch(panpad, ' ');
5597 int top_x, int top_y, int porty, int portx,
5598 int (*pgetc) (WINDOW *),
5601 #if HAVE_GETTIMEOFDAY
5602 struct timeval before, after;
5605 bool pan_lines = FALSE;
5606 bool scrollers = TRUE;
5609 int pxmax, pymax, lowend, highend, c;
5611 getmaxyx(pad, pymax, pxmax);
5612 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5616 #ifdef NCURSES_VERSION
5618 * During shell-out, the user may have resized the window. Adjust
5619 * the port size of the pad to accommodate this. Ncurses automatically
5620 * resizes all of the normal windows to fit on the new screen.
5637 if (c == HELP_KEY_1)
5638 show_panner_legend = !show_panner_legend;
5639 panner_legend(LINES - 4);
5640 panner_legend(LINES - 3);
5641 panner_legend(LINES - 2);
5642 panner_legend(LINES - 1);
5645 pan_lines = !pan_lines;
5646 fill_pad(pad, pan_lines, colored);
5647 pending_pan = FALSE;
5650 #if HAVE_GETTIMEOFDAY
5654 panner_legend(LINES - 1);
5658 scrollers = !scrollers;
5661 /* Move the top-left corner of the pad, keeping the bottom-right
5664 case 'h': /* increase-columns: move left edge to left */
5668 panner_v_cleanup(top_y, top_x, porty);
5673 case 'j': /* decrease-lines: move top-edge down */
5677 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5682 case 'k': /* increase-lines: move top-edge up */
5687 panner_h_cleanup(top_y, top_x, portx);
5691 case 'l': /* decrease-columns: move left-edge to right */
5695 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5700 /* Move the bottom-right corner of the pad, keeping the top-left
5703 case KEY_IC: /* increase-columns: move right-edge to right */
5704 if (portx >= pxmax || portx >= COLS)
5707 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5712 case KEY_IL: /* increase-lines: move bottom-edge down */
5713 if (porty >= pymax || porty >= LINES)
5716 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5721 case KEY_DC: /* decrease-columns: move bottom edge up */
5726 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5730 case KEY_DL: /* decrease-lines */
5735 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5739 case KEY_LEFT: /* pan leftwards */
5746 case KEY_RIGHT: /* pan rightwards */
5747 if (basex + portx - (pymax > porty) < pxmax)
5753 case KEY_UP: /* pan upwards */
5760 case KEY_DOWN: /* pan downwards */
5761 if (basey + porty - (pxmax > portx) < pymax)
5776 basey = pymax - porty;
5786 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5787 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5788 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5790 if (scrollers && (pxmax > portx - 1)) {
5791 int length = (portx - top_x - 1);
5792 float ratio = ((float) length) / ((float) pxmax);
5794 lowend = (int) ((float) top_x + ((float) basex * ratio));
5795 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5797 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5798 if (highend < portx) {
5800 do_h_line(porty - 1, lowend, ' ', highend + 1);
5802 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5805 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5807 if (scrollers && (pymax > porty - 1)) {
5808 int length = (porty - top_y - 1);
5809 float ratio = ((float) length) / ((float) pymax);
5811 lowend = (int) ((float) top_y + ((float) basey * ratio));
5812 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5814 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5815 if (highend < porty) {
5817 do_v_line(lowend, portx - 1, ' ', highend + 1);
5819 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5822 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5824 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5825 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5826 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5829 #if HAVE_GETTIMEOFDAY
5830 gettimeofday(&before, 0);
5832 wnoutrefresh(stdscr);
5837 porty - (pxmax > portx) - 1,
5838 portx - (pymax > porty) - 1);
5841 #if HAVE_GETTIMEOFDAY
5842 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5845 gettimeofday(&after, 0);
5846 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5847 move(LINES - 1, COLS - 12);
5848 printw("Secs: %2.03f", elapsed);
5855 ((c = pgetc(pad)) != KEY_EXIT);
5857 scrollok(stdscr, TRUE); /* reset to driver's default */
5861 padgetch(WINDOW *win)
5866 if ((pending_pan = (count > 0)) != FALSE) {
5868 pending_pan = (count != 0);
5872 switch (c = wGetchar(win)) {
5908 case ERR: /* FALLTHRU */
5914 if (c >= '0' && c <= '9') {
5915 count = count * 10 + (c - '0');
5929 #define PAD_HIGH 200
5930 #define PAD_WIDE 200
5933 pad_test(bool recur GCC_UNUSED)
5934 /* Demonstrate pads. */
5936 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5939 Cannot("cannot create requested pad");
5944 init_pair(1, COLOR_BLACK, COLOR_GREEN);
5945 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5946 wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' '));
5949 fill_pad(panpad, FALSE, TRUE);
5951 panner_legend(LINES - 4);
5952 panner_legend(LINES - 3);
5953 panner_legend(LINES - 2);
5954 panner_legend(LINES - 1);
5956 keypad(panpad, TRUE);
5958 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5959 * We'll still be able to widen it during a test, since that's required
5960 * for testing boundaries.
5962 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, TRUE);
5969 #endif /* HAVE_NEWPAD */
5971 /****************************************************************************
5973 * Tests from John Burnell's PDCurses tester
5975 ****************************************************************************/
5978 Continue(WINDOW *win)
5982 MvWAddStr(win, 10, 1, " Press any key to continue");
5988 flushinp_test(bool recur GCC_UNUSED)
5989 /* Input test, adapted from John Burnell's PDCurses tester */
5991 WINDOW *win = stdscr;
5992 int w, h, bx, by, sw, sh, i;
5997 getmaxyx(win, h, w);
5998 getbegyx(win, by, bx);
6001 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
6006 init_pair(2, COLOR_CYAN, COLOR_BLUE);
6007 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
6010 (void) wattrset(subWin, A_BOLD);
6011 box(subWin, ACS_VLINE, ACS_HLINE);
6012 MvWAddStr(subWin, 2, 1, "This is a subwindow");
6016 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
6017 * it only happened to "work" on SVr4 because that implementation does not
6018 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
6019 * test behavior, we're using 'cbreak()', which will allow a single
6020 * character to return without needing a newline. - T.Dickey 1997/10/11.
6023 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
6025 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
6026 MvWAddStr(win, 3, 1,
6027 "These should be discarded (not echoed) after the subwindow goes away.");
6030 for (i = 0; i < 5; i++) {
6031 MvWPrintw(subWin, 1, 1, "Time = %d", i);
6043 MvWAddStr(win, 2, 1,
6044 "If you were still typing when the window timer expired,");
6045 MvWAddStr(win, 3, 1,
6046 "or else you typed nothing at all while it was running,");
6047 MvWAddStr(win, 4, 1,
6048 "test was invalid. You'll see garbage or nothing at all. ");
6049 MvWAddStr(win, 6, 1, "Press a key");
6055 MvWAddStr(win, 12, 0,
6056 "If you see any key other than what you typed, flushinp() is broken.");
6065 "What you typed should now have been deleted; if not, wdelch() failed.");
6072 /****************************************************************************
6076 ****************************************************************************/
6084 menu_virtualize(int c)
6086 if (c == '\n' || c == KEY_EXIT)
6087 return (MAX_COMMAND + 1);
6089 return (REQ_SCR_ULINE);
6091 return (REQ_SCR_DLINE);
6092 else if (c == 'b' || c == KEY_NPAGE)
6093 return (REQ_SCR_UPAGE);
6094 else if (c == 'f' || c == KEY_PPAGE)
6095 return (REQ_SCR_DPAGE);
6096 else if (c == 'n' || c == KEY_DOWN)
6097 return (REQ_NEXT_ITEM);
6098 else if (c == 'p' || c == KEY_UP)
6099 return (REQ_PREV_ITEM);
6101 return (REQ_TOGGLE_ITEM);
6109 static CONST_MENUS char *animals[] =
6122 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6123 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6128 menu_test(bool recur GCC_UNUSED)
6131 ITEM *items[SIZEOF(animals)];
6133 CONST_MENUS char **ap;
6134 int mrows, mcols, c;
6137 #ifdef NCURSES_MOUSE_VERSION
6138 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6140 MvAddStr(0, 0, "This is the menu test:");
6141 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
6142 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
6144 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
6145 MvAddStr(5, 0, " Press return to exit.");
6148 for (ap = animals; *ap; ap++) {
6149 if ((*ip = new_item(*ap, "")) != 0)
6154 m = new_menu(items);
6156 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
6157 scale_menu(m, &mrows, &mcols);
6159 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6160 set_menu_win(m, menuwin);
6161 keypad(menuwin, TRUE);
6164 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6168 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
6169 if (c == E_NOT_POSTED)
6171 if (c == E_REQUEST_DENIED)
6176 MvPrintw(LINES - 2, 0,
6177 "You chose: %s\n", item_name(current_item(m)));
6178 (void) addstr("Press any key to continue...");
6185 for (ip = items; *ip; ip++)
6187 #ifdef NCURSES_MOUSE_VERSION
6188 mousemask(0, (mmask_t *) 0);
6194 #define T_TBL(name) { #name, name }
6200 T_TBL(TRACE_DISABLE),
6203 T_TBL(TRACE_UPDATE),
6205 T_TBL(TRACE_CHARPUT),
6206 T_TBL(TRACE_ORDINARY),
6208 T_TBL(TRACE_VIRTPUT),
6209 T_TBL(TRACE_IEVENT),
6211 T_TBL(TRACE_ICALLS),
6212 T_TBL(TRACE_CCALLS),
6213 T_TBL(TRACE_DATABASE),
6215 T_TBL(TRACE_MAXIMUM),
6222 tracetrace(unsigned tlevel)
6225 static size_t need = 12;
6229 for (n = 0; t_tbl[n].name != 0; n++)
6230 need += strlen(t_tbl[n].name) + 2;
6231 buf = typeMalloc(char, need);
6233 failed("tracetrace");
6235 _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
6237 _nc_STRCAT(buf, t_tbl[0].name, need);
6238 _nc_STRCAT(buf, ", ", need);
6240 for (n = 1; t_tbl[n].name != 0; n++)
6241 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
6242 _nc_STRCAT(buf, t_tbl[n].name, need);
6243 _nc_STRCAT(buf, ", ", need);
6246 if (buf[strlen(buf) - 2] == ',')
6247 buf[strlen(buf) - 2] = '\0';
6248 _nc_STRCAT(buf, "}", need);
6252 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
6256 run_trace_menu(MENU * m)
6262 bool changed = FALSE;
6263 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
6264 case E_UNKNOWN_COMMAND:
6267 items = menu_items(m);
6268 i = current_item(m);
6269 if (i == items[0]) {
6270 if (item_value(i)) {
6271 for (p = items + 1; *p != 0; p++)
6272 if (item_value(*p)) {
6273 set_item_value(*p, FALSE);
6278 for (p = items + 1; *p != 0; p++)
6279 if (item_value(*p)) {
6280 set_item_value(items[0], FALSE);
6292 trace_set(bool recur GCC_UNUSED)
6293 /* interactively set the trace level */
6296 ITEM *items[SIZEOF(t_tbl)];
6303 MvAddStr(0, 0, "Interactively set trace level:");
6304 MvAddStr(2, 0, " Press space bar to toggle a selection.");
6305 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
6306 MvAddStr(4, 0, " Press return to set the trace level.");
6307 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
6311 for (n = 0; t_tbl[n].name != 0; n++) {
6312 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
6318 m = new_menu(items);
6320 set_menu_format(m, 0, 2);
6321 scale_menu(m, &mrows, &mcols);
6323 menu_opts_off(m, O_ONEVALUE);
6324 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6325 set_menu_win(m, menuwin);
6326 keypad(menuwin, TRUE);
6329 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6333 for (ip = menu_items(m); *ip; ip++) {
6334 unsigned mask = t_tbl[item_index(*ip)].mask;
6336 set_item_value(*ip, _nc_tracing == 0);
6337 else if ((mask & _nc_tracing) == mask)
6338 set_item_value(*ip, TRUE);
6341 while (run_trace_menu(m))
6345 for (ip = menu_items(m); *ip; ip++)
6346 if (item_value(*ip))
6347 newtrace |= t_tbl[item_index(*ip)].mask;
6349 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
6351 MvPrintw(LINES - 2, 0,
6352 "Trace level is %s\n", tracetrace(_nc_tracing));
6353 (void) addstr("Press any key to continue...");
6360 for (ip = items; *ip; ip++)
6366 #endif /* USE_LIBMENU */
6368 /****************************************************************************
6372 ****************************************************************************/
6375 make_label(int frow, int fcol, NCURSES_CONST char *label)
6377 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
6380 set_field_buffer(f, 0, label);
6381 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
6387 make_field(int frow, int fcol, int rows, int cols, bool secure)
6389 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
6392 set_field_back(f, A_UNDERLINE);
6393 set_field_userptr(f, (void *) 0);
6399 display_form(FORM *f)
6404 scale_form(f, &rows, &cols);
6406 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
6408 set_form_sub(f, derwin(w, rows, cols, 1, 2));
6411 if (post_form(f) != E_OK)
6419 WINDOW *w = form_win(f);
6420 WINDOW *s = form_sub(f);
6430 edit_secure(FIELD *me, int c)
6432 int rows, cols, frow, fcol, nrow, nbuf;
6434 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
6436 char *source = field_buffer(me, 1);
6437 size_t have = (source ? strlen(source) : 0) + 1;
6438 size_t need = 80 + have;
6439 char *temp = malloc(need);
6443 _nc_STRNCPY(temp, source ? source : "", have + 1);
6444 len = (size_t) (char *) field_userptr(me);
6446 if (isgraph(c) && (len + 1) < sizeof(temp)) {
6447 temp[len++] = (char) c;
6449 set_field_buffer(me, 1, temp);
6469 case REQ_RIGHT_CHAR:
6471 c = 0; /* we don't want to do inline editing */
6476 set_field_buffer(me, 1, temp);
6483 set_field_buffer(me, 1, temp);
6488 set_field_userptr(me, (void *) len);
6496 form_virtualize(FORM *f, WINDOW *w)
6499 static const struct {
6503 { CTRL('A'), REQ_NEXT_CHOICE },
6504 { CTRL('B'), REQ_PREV_WORD },
6505 { CTRL('C'), REQ_CLR_EOL },
6506 { CTRL('D'), REQ_DOWN_FIELD },
6507 { CTRL('E'), REQ_END_FIELD },
6508 { CTRL('F'), REQ_NEXT_PAGE },
6509 { CTRL('G'), REQ_DEL_WORD },
6510 { CTRL('H'), REQ_DEL_PREV },
6511 { CTRL('I'), REQ_INS_CHAR },
6512 { CTRL('K'), REQ_CLR_EOF },
6513 { CTRL('L'), REQ_LEFT_FIELD },
6514 { CTRL('M'), REQ_NEW_LINE },
6515 { CTRL('N'), REQ_NEXT_FIELD },
6516 { CTRL('O'), REQ_INS_LINE },
6517 { CTRL('P'), REQ_PREV_FIELD },
6518 { CTRL('R'), REQ_RIGHT_FIELD },
6519 { CTRL('S'), REQ_BEG_FIELD },
6520 { CTRL('U'), REQ_UP_FIELD },
6521 { CTRL('V'), REQ_DEL_CHAR },
6522 { CTRL('W'), REQ_NEXT_WORD },
6523 { CTRL('X'), REQ_CLR_FIELD },
6524 { CTRL('Y'), REQ_DEL_LINE },
6525 { CTRL('Z'), REQ_PREV_CHOICE },
6526 { ESCAPE, MAX_FORM_COMMAND + 1 },
6527 { KEY_BACKSPACE, REQ_DEL_PREV },
6528 { KEY_DOWN, REQ_DOWN_CHAR },
6529 { KEY_END, REQ_LAST_FIELD },
6530 { KEY_HOME, REQ_FIRST_FIELD },
6531 { KEY_LEFT, REQ_LEFT_CHAR },
6532 { KEY_LL, REQ_LAST_FIELD },
6533 { KEY_NEXT, REQ_NEXT_FIELD },
6534 { KEY_NPAGE, REQ_NEXT_PAGE },
6535 { KEY_PPAGE, REQ_PREV_PAGE },
6536 { KEY_PREVIOUS, REQ_PREV_FIELD },
6537 { KEY_RIGHT, REQ_RIGHT_CHAR },
6538 { KEY_UP, REQ_UP_CHAR },
6539 { QUIT, MAX_FORM_COMMAND + 1 }
6543 static int mode = REQ_INS_MODE;
6544 int c = wGetchar(w);
6545 FIELD *me = current_field(f);
6546 bool current = TRUE;
6548 if (c == CTRL(']')) {
6549 if (mode == REQ_INS_MODE) {
6550 mode = REQ_OVL_MODE;
6552 mode = REQ_INS_MODE;
6557 for (n = 0; n < SIZEOF(lookup); n++) {
6558 if (lookup[n].code == c) {
6559 c = lookup[n].result;
6564 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
6567 * Force the field that the user is typing into to be in reverse video,
6568 * while the other fields are shown underlined.
6583 case REQ_LEFT_FIELD:
6585 case REQ_RIGHT_CHAR:
6589 current = (c < KEY_MAX);
6593 c = edit_secure(me, c);
6594 set_field_back(me, A_REVERSE);
6596 c = edit_secure(me, c);
6597 set_field_back(me, A_UNDERLINE);
6603 my_form_driver(FORM *form, int c)
6605 if (c == (MAX_FORM_COMMAND + 1)
6606 && form_driver(form, REQ_VALIDATION) == E_OK)
6614 #ifdef NCURSES_VERSION
6615 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6616 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6618 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6619 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6623 * Allow a middle initial, optionally with a '.' to end it.
6626 FIELDCHECK_CB(mi_field_check)
6628 char *s = field_buffer(fld, 0);
6632 for (n = 0; s[n] != '\0'; ++n) {
6639 } else if (isspace(UChar(s[n]))) {
6644 if (!isspace(UChar(s[n])))
6650 /* force the form to display a leading capital */
6651 if (islower(UChar(s[0]))) {
6652 s[0] = (char) toupper(UChar(s[0]));
6653 set_field_buffer(fld, 0, s);
6659 CHAR_CHECK_CB(mi_char_check)
6661 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6665 * Passwords should be at least 6 characters.
6668 FIELDCHECK_CB(pw_field_check)
6670 char *s = field_buffer(fld, 0);
6673 for (n = 0; s[n] != '\0'; ++n) {
6674 if (isspace(UChar(s[n]))) {
6683 CHAR_CHECK_CB(pw_char_check)
6685 return (isgraph(ch) ? TRUE : FALSE);
6689 form_test(bool recur GCC_UNUSED)
6692 FIELD *f[12], *secure;
6693 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6694 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6698 #ifdef NCURSES_MOUSE_VERSION
6699 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6703 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6704 addstr("^N -- go to next field ^P -- go to previous field\n");
6705 addstr("Home -- go to first field End -- go to last field\n");
6706 addstr("^L -- go to field to left ^R -- go to field to right\n");
6707 addstr("^U -- move upward to field ^D -- move downward to field\n");
6708 addstr("^W -- go to next word ^B -- go to previous word\n");
6709 addstr("^S -- go to start of field ^E -- go to end of field\n");
6710 addstr("^H -- delete previous char ^Y -- delete line\n");
6711 addstr("^G -- delete current word ^C -- clear to end of line\n");
6712 addstr("^K -- clear to end of field ^X -- clear field\n");
6713 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6715 MvAddStr(4, 57, "Forms Entry Test");
6719 /* describe the form */
6720 memset(f, 0, sizeof(f));
6721 f[n++] = make_label(0, 15, "Sample Form");
6723 f[n++] = make_label(2, 0, "Last Name");
6724 f[n++] = make_field(3, 0, 1, 18, FALSE);
6725 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6727 f[n++] = make_label(2, 20, "First Name");
6728 f[n++] = make_field(3, 20, 1, 12, FALSE);
6729 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6731 f[n++] = make_label(2, 34, "Middle Name");
6732 f[n++] = make_field(3, 34, 1, 12, FALSE);
6733 set_field_type(f[n - 1], fty_middle);
6735 f[n++] = make_label(5, 0, "Comments");
6736 f[n++] = make_field(6, 0, 4, 46, FALSE);
6738 f[n++] = make_label(5, 20, "Password:");
6740 f[n++] = make_field(5, 30, 1, 9, TRUE);
6741 set_field_type(f[n - 1], fty_passwd);
6744 if ((form = new_form(f)) != 0) {
6752 nonl(); /* lets us read ^M's */
6754 switch (form_driver(form, c = form_virtualize(form, w))) {
6756 MvAddStr(5, 57, field_buffer(secure, 1));
6760 case E_UNKNOWN_COMMAND:
6761 finished = my_form_driver(form, c);
6773 for (c = 0; f[c] != 0; c++)
6775 free_fieldtype(fty_middle);
6776 free_fieldtype(fty_passwd);
6780 #ifdef NCURSES_MOUSE_VERSION
6781 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6785 #endif /* USE_LIBFORM */
6787 /****************************************************************************
6791 ****************************************************************************/
6793 #if HAVE_COPYWIN /* ...and overlay, overwrite */
6795 static const int overlap_HEAD = 1;
6796 static const int overlap_FOOT = 6;
6804 getmaxyx(stdscr, y, x);
6805 if (y < 23 || x < 80) {
6806 Cannot("The screen is too small for this test");
6809 int ymax = y - (overlap_HEAD + overlap_FOOT);
6810 int high = ymax / 5; /* equal-sized parts for cross */
6811 int xmax = x - 2; /* margin */
6812 int wide = (xmax / 5) & ~1;
6821 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6822 lmar = (xmax - (5 * wide)) / 2;
6825 result = newwin(3 * high, 3 * wide, tmar, lmar);
6827 result = newwin(3 * high, 3 * wide, tmar + 2 * high, lmar + 2 * wide);
6838 for (row = overlap_HEAD; row < LINES - overlap_FOOT; ++row) {
6845 move_overlap(int shift, WINDOW *win1)
6847 int ymax = getmaxy(stdscr) - (overlap_HEAD + overlap_FOOT);
6848 int high = ymax / 5; /* equal-sized parts for cross */
6850 int xmax1 = getmaxx(win1) + 1;
6851 int lmar1 = (COLS - (5 * (xmax1) / 3)) / 2;
6856 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6858 rc = mvwin(win1, tmar, lmar1 + shift);
6863 fillwin(WINDOW *win, char ch)
6868 getmaxyx(win, y1, x1);
6869 for (y = 0; y < y1; y++) {
6871 for (x = 0; x < x1; x++)
6872 waddch(win, UChar(ch));
6876 #define InCross(x,y, x1,y1) \
6877 (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3)) \
6878 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3))))
6881 crosswin(WINDOW *win, char ch)
6887 getmaxyx(win, y1, x1);
6888 for (y = 0; y < y1; y++) {
6889 for (x = 0; x < x1; x += xw) {
6890 if (InCross(x, y, x1, y1)) {
6892 waddch(win, UChar(ch));
6899 * Match "crosswin()", but using line-drawing characters. This could be done
6900 * a little simpler using box(), but the reason for this example is to test
6901 * hline/vline and addch with line-drawing vs the copy/overlay functions.
6904 crossbox(WINDOW *win)
6909 getmaxyx(win, y1, x1);
6914 mvwhline(win, 0, (xmax / 3), ACS_HLINE, (xmax / 3));
6915 mvwhline(win, ymax / 3, 0, ACS_HLINE, xmax);
6916 mvwhline(win, ((2 * ymax) / 3) - 1, 0, ACS_HLINE, xmax);
6917 mvwhline(win, y1 - 1, (xmax / 3), ACS_HLINE, (xmax / 3));
6919 mvwvline(win, (ymax / 3), 0, ACS_VLINE, (ymax / 3));
6920 mvwvline(win, 0, xmax / 3, ACS_VLINE, ymax);
6921 mvwvline(win, 0, ((2 * xmax) / 3) - 1, ACS_VLINE, ymax);
6922 mvwvline(win, (ymax / 3), x1 - 1, ACS_VLINE, (ymax / 3));
6924 mvwaddch(win, 0, (xmax / 3), ACS_ULCORNER);
6925 mvwaddch(win, 0, ((2 * xmax) / 3) - 1, ACS_URCORNER);
6926 mvwaddch(win, y1 - 1, (xmax / 3), ACS_LLCORNER);
6927 mvwaddch(win, y1 - 1, ((2 * xmax) / 3) - 1, ACS_LRCORNER);
6929 mvwaddch(win, (ymax / 3), 0, ACS_ULCORNER);
6930 mvwaddch(win, ((2 * ymax) / 3) - 1, 0, ACS_LLCORNER);
6931 mvwaddch(win, (ymax / 3), x1 - 1, ACS_URCORNER);
6932 mvwaddch(win, ((2 * ymax) / 3) - 1, x1 - 1, ACS_LRCORNER);
6934 mvwaddch(win, (ymax / 3), (xmax / 3), ACS_PLUS);
6935 mvwaddch(win, (ymax / 3), ((2 * xmax) / 3) - 1, ACS_PLUS);
6936 mvwaddch(win, ((2 * ymax) / 3) - 1, ((2 * xmax) / 3) - 1, ACS_PLUS);
6937 mvwaddch(win, ((2 * ymax) / 3) - 1, (xmax / 3), ACS_PLUS);
6948 #define OVERLAP_FLAVORS 6
6957 #define LimitFILL() UseColors ? 4 : 2
6960 otDRAW_text_cross = 0
6967 #define LimitDRAW() UseColors ? 5 : 3
6970 otCOPY_overwrite = 0
6976 #define LimitCOPY() 4
6979 overlap_helpitem(int state, int item, char *message)
6981 int row = (item / 2);
6982 int col = ((item % 2) ? COLS / 2 : 0);
6984 move(LINES - 6 + row, col);
6985 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6990 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6992 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
6994 switch ((otFILL) flavor) {
6996 (void) wattrset(win, A_NORMAL);
6999 (void) wattrset(win, A_BOLD);
7002 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
7003 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
7006 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
7007 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
7013 overlap_test_2_attr(WINDOW *win, int flavor, int col)
7015 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
7017 switch ((otDRAW) flavor) {
7018 case otDRAW_text_cross:
7021 case otDRAW_line_box:
7024 case otDRAW_line_cross:
7028 init_pair(cpair, COLOR_RED, COLOR_GREEN);
7029 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
7031 case otDRAW_reset_bg:
7032 wbkgdset(win, ' ' | A_NORMAL);
7038 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
7041 int limit[OVERLAP_FLAVORS];
7045 state += OVERLAP_FLAVORS;
7046 state = state % OVERLAP_FLAVORS;
7047 assert(state >= 0 && state < OVERLAP_FLAVORS);
7049 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
7052 const char *ths = col ? "B" : "A";
7053 const char *tht = col ? "A" : "B";
7055 switch ((otBASE) row) {
7056 case otBASE_refresh:
7059 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7060 "refresh %s, then %s, then doupdate.", ths, tht);
7063 limit[row] = LimitFILL();
7064 flavors[row] %= limit[row];
7065 overlap_test_1_attr(stdscr, flavors[row], col);
7066 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7067 "fill window %s with letter %s.", ths, ths);
7070 limit[row] = LimitDRAW();
7071 flavors[row] %= limit[row];
7072 switch ((otDRAW) flavors[row]) {
7073 case otDRAW_text_cross:
7074 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7075 "cross text-pattern in window %s.", ths);
7077 case otDRAW_line_box:
7078 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7079 "draw line-box in window %s.", ths);
7081 case otDRAW_line_cross:
7082 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7083 "draw line-cross in window %s.", ths);
7086 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7087 "set background of window %s.", ths);
7089 case otDRAW_reset_bg:
7090 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7091 "reset background of window %s.", ths);
7098 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7099 "clear window %s.", ths);
7102 limit[row] = LimitCOPY();
7103 flavors[row] %= limit[row];
7104 switch ((otCOPY) flavors[row]) {
7105 case otCOPY_overwrite:
7106 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7107 "overwrite %s onto %s.", ths, tht);
7110 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7111 "copywin(FALSE) %s onto %s.", ths, tht);
7114 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7115 "copywin(TRUE) %s onto %s.", ths, tht);
7117 case otCOPY_overlay:
7118 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7119 "overlay %s onto %s.", ths, tht);
7124 overlap_helpitem(state, item, msg);
7125 (void) wattrset(stdscr, A_NORMAL);
7126 wbkgdset(stdscr, ' ' | A_NORMAL);
7129 printw("^Q/ESC = terminate test. </> shift. Up/down/space select (row %d",
7131 if (limit[state] > 1)
7132 printw(" test %d:%d", 1 + flavors[state], limit[state]);
7140 overlap_test_0(WINDOW *a, WINDOW *b)
7150 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
7152 overlap_test_1_attr(a, flavor, col);
7154 (void) wattrset(a, A_NORMAL);
7158 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
7160 overlap_test_2_attr(a, flavor, col);
7161 switch ((otDRAW) flavor) {
7162 case otDRAW_text_cross:
7165 case otDRAW_line_box:
7168 case otDRAW_line_cross:
7172 /* done in overlap_test_2_attr */
7174 case otDRAW_reset_bg:
7175 /* done in overlap_test_2_attr */
7181 overlap_test_3(WINDOW *a)
7188 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
7190 switch ((otCOPY) flavor) {
7191 case otCOPY_overwrite:
7195 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
7198 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
7200 case otCOPY_overlay:
7206 /* test effects of overlapping windows */
7208 overlap_test(bool recur GCC_UNUSED)
7210 WINDOW *win1, *win2;
7212 int shift = 0, last_refresh = -1;
7213 int state, flavor[OVERLAP_FLAVORS];
7215 if ((win1 = make_overlap(0)) == 0) {
7217 } else if ((win2 = make_overlap(1)) == 0) {
7226 printw("Test wnoutrefresh() for two overlapping windows:");
7228 memset(flavor, 0, sizeof(flavor));
7229 state = overlap_help(0, flavor);
7231 while (!isQuit(ch = Getchar(), TRUE)) {
7233 case 'a': /* refresh window A first, then B */
7234 overlap_test_0(win1, win2);
7237 case 'b': /* refresh window B first, then A */
7238 overlap_test_0(win2, win1);
7241 case 'c': /* fill window A so it's visible */
7242 overlap_test_1(flavor[otBASE_fill], 0, win1, 'A');
7245 case 'd': /* fill window B so it's visible */
7246 overlap_test_1(flavor[otBASE_fill], 1, win2, 'B');
7249 case 'e': /* cross test pattern in window A */
7250 overlap_test_2(flavor[otBASE_draw], 0, win1, 'A');
7253 case 'f': /* cross test pattern in window A */
7254 overlap_test_2(flavor[otBASE_draw], 1, win2, 'B');
7257 case 'g': /* clear window A */
7258 overlap_test_3(win1);
7261 case 'h': /* clear window B */
7262 overlap_test_3(win2);
7265 case 'i': /* overwrite A onto B */
7266 overlap_test_4(flavor[otBASE_copy], win1, win2);
7269 case 'j': /* overwrite B onto A */
7270 overlap_test_4(flavor[otBASE_copy], win2, win1);
7275 state = overlap_help(state + 1, flavor);
7280 state = overlap_help(state - 1, flavor);
7285 state = overlap_help(state, flavor);
7289 state = overlap_help(state, flavor);
7314 if (move_overlap(shift, win1) != OK) {
7316 shift += (ch == '>') ? -1 : 1;
7317 } else if (last_refresh > 0) {
7319 wnoutrefresh(stdscr);
7320 if (last_refresh == 'a')
7321 overlap_test_0(win1, win2);
7323 overlap_test_0(win2, win1);
7339 #if USE_WIDEC_SUPPORT
7341 x_fillwin(WINDOW *win, wchar_t ch)
7346 getmaxyx(win, y1, x1);
7348 for (y = 0; y < y1; y++) {
7350 for (x = 0; x < x1; x++)
7351 waddnwstr(win, &ch, 1);
7356 x_crosswin(WINDOW *win, wchar_t ch)
7362 getmaxyx(win, y1, x1);
7363 for (y = 0; y < y1; y++) {
7364 for (x = 0; x < x1; x += xw) {
7365 if (InCross(x, y, x1, y1)) {
7367 waddnwstr(win, &ch, 1);
7374 x_overlap_test_1(int flavor, int col, WINDOW *a, wchar_t fill)
7376 overlap_test_1_attr(a, flavor, col);
7378 (void) wattrset(a, A_NORMAL);
7382 x_overlap_test_2(int flavor, int col, WINDOW *a, wchar_t fill)
7384 overlap_test_2_attr(a, flavor, col);
7385 switch ((otDRAW) flavor) {
7386 case otDRAW_text_cross:
7387 x_crosswin(a, fill);
7389 case otDRAW_line_box:
7392 case otDRAW_line_cross:
7396 /* done in overlap_test_2_attr */
7398 case otDRAW_reset_bg:
7399 /* done in overlap_test_2_attr */
7404 /* test effects of overlapping windows */
7406 x_overlap_test(bool recur GCC_UNUSED)
7408 const wchar_t WIDE_A = 0xff21;
7409 const wchar_t WIDE_B = 0xff22;
7410 WINDOW *win1, *win2;
7412 int shift = 0, last_refresh = -1;
7413 int state, flavor[OVERLAP_FLAVORS];
7415 if ((win1 = make_overlap(0)) == 0) {
7417 } else if ((win2 = make_overlap(1)) == 0) {
7426 printw("Test wnoutrefresh() for overlapping windows with double-cell characters:");
7428 memset(flavor, 0, sizeof(flavor));
7429 state = overlap_help(0, flavor);
7431 while (!isQuit(ch = Getchar(), TRUE)) {
7433 case 'a': /* refresh window A first, then B */
7434 overlap_test_0(win1, win2);
7437 case 'b': /* refresh window B first, then A */
7438 overlap_test_0(win2, win1);
7441 case 'c': /* fill window A so it's visible */
7442 x_overlap_test_1(flavor[otBASE_fill], 0, win1, WIDE_A);
7445 case 'd': /* fill window B so it's visible */
7446 x_overlap_test_1(flavor[otBASE_fill], 1, win2, WIDE_B);
7449 case 'e': /* cross test pattern in window A */
7450 x_overlap_test_2(flavor[otBASE_draw], 0, win1, WIDE_A);
7453 case 'f': /* cross test pattern in window A */
7454 x_overlap_test_2(flavor[otBASE_draw], 1, win2, WIDE_B);
7457 case 'g': /* clear window A */
7458 overlap_test_3(win1);
7461 case 'h': /* clear window B */
7462 overlap_test_3(win2);
7465 case 'i': /* overwrite A onto B */
7466 overlap_test_4(flavor[otBASE_copy], win1, win2);
7469 case 'j': /* overwrite B onto A */
7470 overlap_test_4(flavor[otBASE_copy], win2, win1);
7475 state = overlap_help(state + 1, flavor);
7480 state = overlap_help(state - 1, flavor);
7485 state = overlap_help(state, flavor);
7489 state = overlap_help(state, flavor);
7514 if (move_overlap(shift, win1) != OK) {
7516 shift += (ch == '>') ? -1 : 1;
7517 } else if (last_refresh > 0) {
7519 wnoutrefresh(stdscr);
7520 if (last_refresh == 'a')
7521 overlap_test_0(win1, win2);
7523 overlap_test_0(win2, win1);
7538 #endif /* USE_WIDEC_SUPPORT */
7540 #endif /* HAVE_COPYWIN */
7543 show_setting_name(const char *name)
7545 printw("%-25s ", name);
7549 show_string_setting(const char *name, const char *value)
7551 show_setting_name(name);
7553 printw("\"%s\"", value);
7563 show_number_setting(const char *name, int value)
7565 show_setting_name(name);
7567 printw("%d", value);
7570 printw("%d", value);
7577 show_boolean_setting(const char *name, int value)
7579 show_setting_name(name);
7581 printw("%s", value ? "TRUE" : "FALSE");
7584 printw("%d", value);
7591 settings_test(bool recur GCC_UNUSED)
7593 #if USE_WIDEC_SUPPORT
7598 show_string_setting("termname", termname());
7599 show_string_setting("longname", longname());
7600 show_number_setting("baudrate", baudrate());
7601 if (erasechar() > 0) {
7602 show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar()));
7603 show_string_setting("keyname(erasechar)", keyname(erasechar()));
7605 if (killchar() > 0) {
7606 show_string_setting("unctrl(killchar)", unctrl((chtype) killchar()));
7607 show_string_setting("keyname(killchar)", keyname(killchar()));
7609 #if USE_WIDEC_SUPPORT
7610 if (erasewchar(&ch) == OK) {
7611 show_string_setting("key_name(erasewchar)", key_name(ch));
7613 if (killwchar(&ch) == OK) {
7614 show_string_setting("key_name(killwchar)", key_name(ch));
7617 show_boolean_setting("has_ic", has_ic());
7618 show_boolean_setting("has_il", has_il());
7619 show_boolean_setting("has_colors", has_colors());
7620 #if HAVE_COLOR_CONTENT
7621 show_boolean_setting("can_change_color", can_change_color());
7629 /****************************************************************************
7633 ****************************************************************************/
7638 static const char *const tbl[] =
7640 "Usage: ncurses [options]"
7643 #ifdef NCURSES_VERSION
7644 ," -a f,b set default-colors (assumed white-on-black)"
7645 ," -d use default-colors if terminal supports them"
7648 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
7651 ," -e fmt specify format for soft-keys test (e)"
7654 ," -f rip-off footer line (can repeat)"
7655 ," -h rip-off header line (can repeat)"
7657 ," -m do not use colors"
7658 #if HAVE_COLOR_CONTENT
7659 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
7662 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
7664 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_WIN32)
7665 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
7668 ," -t mask specify default trace-level (may toggle with ^T)"
7670 #if HAVE_COLOR_CONTENT
7671 ," -x use xterm-compatible control for reading color palette"
7675 for (n = 0; n < SIZEOF(tbl); n++)
7676 fprintf(stderr, "%s\n", tbl[n]);
7677 ExitProgram(EXIT_FAILURE);
7681 set_terminal_modes(void)
7686 scrollok(stdscr, TRUE);
7687 idlok(stdscr, TRUE);
7688 keypad(stdscr, TRUE);
7693 announce_sig(int sig)
7695 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
7701 rip_footer(WINDOW *win, int cols)
7703 wbkgd(win, A_REVERSE);
7706 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
7712 rip_header(WINDOW *win, int cols)
7714 wbkgd(win, A_REVERSE);
7717 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
7721 #endif /* HAVE_RIPOFFLINE */
7726 #if USE_WIDEC_SUPPORT
7729 int (*narrow_func) (bool);
7730 int (*wide_func) (bool);
7734 #define BOTH(a) a, x_ ## a
7735 #define ONLY(a) a, NULL
7736 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7740 int (*narrow_func) (bool);
7746 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7749 static MyCmds cmds[] =
7751 CMDS(TRUE, BOTH(getch_test), 'a', "keyboard and mouse input test"),
7752 CMDS(TRUE, BOTH(attr_test), 'b', "character attribute test"),
7753 CMDS(TRUE, BOTH(color_test), 'c', "color test pattern"),
7754 #if HAVE_COLOR_CONTENT
7755 CMDS(FALSE, ONLY(color_edit), 'd', "edit RGB color values"),
7758 CMDS(TRUE, BOTH(slk_test), 'e', "exercise soft keys"),
7760 CMDS(TRUE, BOTH(acs_test), 'f', "display ACS characters"),
7761 CMDS(TRUE, ONLY(scroll_test), 'g', "display windows and scrolling"),
7762 CMDS(TRUE, ONLY(flushinp_test), 'i', "test flushinp()"),
7763 CMDS(TRUE, ONLY(sgr_attr_test), 'k', "display character attributes"),
7765 CMDS(TRUE, ONLY(menu_test), 'm', "exercise menu library"),
7768 CMDS(TRUE, BOTH(panel_test), 'o', "exercise panel library"),
7771 CMDS(TRUE, ONLY(pad_test), 'p', "exercise pad features"),
7773 CMDS(TRUE, ONLY(NULL), 'q', "quit"),
7775 CMDS(TRUE, ONLY(form_test), 'r', "exercise form library"),
7778 CMDS(TRUE, BOTH(overlap_test), 's', "overlapping-refresh test"),
7780 #if USE_LIBMENU && defined(TRACE)
7781 CMDS(TRUE, ONLY(trace_set), 't', "set trace level"),
7783 CMDS(TRUE, ONLY(settings_test), 'v', "show terminal name and settings"),
7784 CMDS(FALSE, ONLY(NULL), '?', "repeat this command summary")
7793 printf("This is the ncurses main menu (uppercase for wide-characters)\n");
7794 for (n = 0; n < SIZEOF(cmds); ++n) {
7795 if (top || cmds[n].recur) {
7797 #if USE_WIDEC_SUPPORT
7798 if (cmds[n].wide_func) {
7799 printf("%c,", toupper(cmds[n].code));
7802 printf("%c\t= %s\n", cmds[n].code, cmds[n].help);
7806 (void) fputs("> ", stdout);
7807 (void) fflush(stdout); /* necessary under SVr4 curses */
7810 * This used to be an 'fgets()' call (until 1996/10). However with
7811 * some runtime libraries, mixing stream I/O and 'read()' causes the
7812 * input stream to be flushed when switching between the two.
7817 if (read(fileno(stdin), &ch, (size_t) 1) <= 0) {
7818 int save_err = errno;
7820 if (save_err == EINTR) {
7823 } else if (command == 0) {
7827 } else if (command == 0 && !isspace(UChar(ch))) {
7829 } else if (ch == '\n' || ch == '\r') {
7830 if ((command == 'd') && !top) {
7831 (void) fputs("Do not nest test-d\n", stdout);
7836 (void) fputs("> ", stdout);
7837 (void) fflush(stdout);
7842 for (n = 0; n < SIZEOF(cmds); ++n) {
7843 if (cmds[n].code == command) {
7844 doit = cmds[n].narrow_func;
7847 #if USE_WIDEC_SUPPORT
7848 if (toupper(cmds[n].code) == command) {
7849 doit = cmds[n].wide_func;
7855 if (doit != NULL && doit(FALSE) == OK) {
7857 * This may be overkill; it's intended to reset everything back
7858 * to the initial terminal modes so that tests don't get in
7862 set_terminal_modes();
7867 if (command == '?') {
7868 (void) puts("This is the ncurses capability tester.");
7870 puts("You may select a test from the main menu by typing the");
7872 puts("key letter of the choice (the letter to left of the =)");
7874 puts("at the > prompt. Type `q' to exit.");
7882 /*+-------------------------------------------------------------------------
7884 --------------------------------------------------------------------------*/
7887 main(int argc, char *argv[])
7891 #ifdef NCURSES_VERSION_PATCH
7892 #if HAVE_USE_DEFAULT_COLORS
7893 int default_fg = COLOR_WHITE;
7894 int default_bg = COLOR_BLACK;
7895 bool default_colors = FALSE;
7896 #if HAVE_ASSUME_DEFAULT_COLORS
7897 bool assumed_colors = FALSE;
7901 bool monochrome = FALSE;
7902 #if HAVE_COLOR_CONTENT
7903 bool xterm_colors = FALSE;
7904 char *palette_file = 0;
7907 setlocale(LC_ALL, "");
7909 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:x")) != -1) {
7911 #ifdef NCURSES_VERSION_PATCH
7912 #if HAVE_USE_DEFAULT_COLORS
7913 #if HAVE_ASSUME_DEFAULT_COLORS
7915 assumed_colors = TRUE;
7916 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
7918 default_fg = COLOR_WHITE;
7921 default_bg = COLOR_BLACK;
7927 default_colors = TRUE;
7937 my_e_param = atoi(optarg);
7938 #ifdef NCURSES_VERSION
7939 if (my_e_param > 3) /* allow extended layouts */
7948 ripoffline(-1, rip_footer);
7951 ripoffline(1, rip_header);
7953 #endif /* HAVE_RIPOFFLINE */
7957 #if HAVE_COLOR_CONTENT
7959 palette_file = optarg;
7964 nap_msec = (int) atol(optarg);
7967 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_WIN32)
7974 save_trace = (unsigned) strtol(optarg, 0, 0);
7977 #if HAVE_COLOR_CONTENT
7979 xterm_colors = TRUE;
7988 * If there's no menus (unlikely for ncurses!), then we'll have to set
7989 * tracing on initially, just in case the user wants to test something that
7990 * doesn't involve wGetchar.
7993 /* enable debugging */
7997 if (!isatty(fileno(stdin)))
7999 #endif /* USE_LIBMENU */
8003 /* tell it we're going to play with soft keys */
8004 slk_init(my_e_param);
8008 /* set up null signal catcher so we can see what interrupts to getch do */
8009 signal(SIGUSR1, announce_sig);
8012 /* we must initialize the curses data structure only once */
8016 set_terminal_modes();
8019 /* tests, in general, will want these modes */
8020 UseColors = (bool) (monochrome ? FALSE : has_colors());
8024 #ifdef NCURSES_VERSION_PATCH
8025 MaxColors = COLORS; /* was > 16 ? 16 : COLORS */
8026 #if HAVE_USE_DEFAULT_COLORS
8027 if (default_colors) {
8028 use_default_colors();
8031 #if HAVE_ASSUME_DEFAULT_COLORS
8033 assume_default_colors(default_fg, default_bg);
8036 #else /* normal SVr4 curses */
8037 MaxColors = COLORS; /* was > 8 ? 8 : COLORS */
8039 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
8041 #if HAVE_COLOR_CONTENT
8042 if (can_change_color()) {
8043 init_all_colors(xterm_colors, palette_file);
8049 * Return to terminal mode, so we're guaranteed of being able to
8050 * select terminal commands even if the capabilities are wrong.
8054 #if HAVE_CURSES_VERSION
8055 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
8056 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
8057 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
8058 NCURSES_VERSION_MAJOR,
8059 NCURSES_VERSION_MINOR,
8060 NCURSES_VERSION_PATCH);
8062 (void) puts("Welcome to ncurses. Press ? for help.");
8067 ExitProgram(EXIT_SUCCESS);
8070 /* ncurses.c ends here */