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.520 2019/12/07 19:04:52 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;
213 curses_trace(_nc_tracing);
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;
347 curses_trace(_nc_tracing);
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));
3740 show_1_acs(int n, int repeat, const char *name, chtype code)
3742 const int height = 16;
3743 int row = 2 + (n % height);
3744 int col = (n / height) * COLS / 2;
3746 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3749 } while (--repeat > 0);
3754 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3755 /* display the ACS character set */
3759 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3763 MvAddStr(0, 20, "Display of the ACS Character Set");
3767 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3768 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3769 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3770 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3772 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3773 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3774 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3775 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3777 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3778 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3781 * HPUX's ACS definitions are broken here. Just give up.
3783 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3784 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3785 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3786 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3787 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3789 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3790 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3791 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3792 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3793 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3794 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3795 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3796 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3797 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3799 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3800 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3801 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3803 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3804 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3805 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3806 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3807 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3808 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3814 acs_test(bool recur GCC_UNUSED)
3818 char *term = getenv("TERM");
3819 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3822 chtype attr = A_NORMAL;
3825 int fg = COLOR_BLACK;
3826 int bg = COLOR_BLACK;
3827 unsigned at_code = 0;
3828 NCURSES_PAIRS_T pair = 0;
3829 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3830 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3831 unsigned my_size = init_attr_list(my_list, termattrs());
3839 ToggleAcs(last_show_acs, show_acs_chars);
3843 ToggleAcs(last_show_acs, show_pc_chars);
3848 if (pagesize == 32) {
3855 ToggleAcs(last_show_acs, show_box_chars);
3881 if (repeat < (COLS / 4))
3889 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3890 || cycle_colors(c, &fg, &bg, &pair)) {
3897 if (pagesize != 32) {
3898 show_256_chars(repeat, attr, pair);
3899 } else if (last_show_acs != 0) {
3900 last_show_acs(repeat, attr, pair);
3902 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3905 MvPrintw(LINES - 3, 0,
3906 "Note: ANSI terminals may not display C1 characters.");
3907 MvPrintw(LINES - 2, 0,
3908 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3911 MvPrintw(LINES - 1, 0,
3912 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3913 my_list[at_code].name,
3916 MvPrintw(LINES - 1, 0,
3917 "v/V cycles through video attributes (%s).",
3918 my_list[at_code].name);
3921 } while (!isQuit(c = Getchar(), TRUE));
3929 #if USE_WIDEC_SUPPORT
3931 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3937 TEST_CCHAR(src, count, {
3938 attr |= (test_attrs & A_ALTCHARSET);
3939 setcchar(dst, test_wch, attr, pair, NULL);
3948 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3949 * display. If there are no repeats, we could normally display 16 lines of 64
3950 * characters (1024 total). However, taking repeats and double-width cells
3951 * into account, use 256 characters for the page.
3954 show_paged_widechars(unsigned base,
3959 NCURSES_PAIRS_T pair)
3961 unsigned first = base * pagesize;
3962 unsigned last = first + pagesize - 1;
3970 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3973 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
3974 int row = (2 + (int) (code - (wchar_t) first) / per_line);
3975 int col = 5 * ((int) code % per_line);
3978 memset(&codes, 0, sizeof(codes));
3980 setcchar(&temp, codes, attr, pair, 0);
3982 if (wcwidth(code) == 0 && code != 0) {
3983 AddCh((chtype) space |
3984 (A_REVERSE ^ attr) |
3985 (attr_t) COLOR_PAIR(pair));
3988 for (count = 1; count < repeat; ++count) {
3995 show_upper_widechars(unsigned first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3999 unsigned last = first + 31;
4003 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
4006 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
4007 int row = 2 + ((int) (code - (wchar_t) first) % 16);
4008 int col = ((int) (code - (wchar_t) first) / 16) * COLS / 2;
4013 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
4014 "%3ld (0x%lx)", (long) code, (long) code);
4015 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
4017 memset(&codes, 0, sizeof(codes));
4019 setcchar(&temp, codes, attr, pair, 0);
4025 * Give non-spacing characters something to combine with. If we
4026 * don't, they'll bunch up in a heap on the space after the ":".
4027 * Mark them with reverse-video to make them simpler to find on
4030 if (wcwidth(code) == 0) {
4031 AddCh((chtype) space |
4032 (A_REVERSE ^ attr) |
4033 (attr_t) COLOR_PAIR(pair));
4036 * This uses echo_wchar(), for comparison with the normal 'f'
4037 * test (and to make a test-case for echo_wchar()). The screen
4038 * may flicker because the erase() at the top of the function
4039 * is met by the builtin refresh() in echo_wchar().
4043 * The repeat-count may make text wrap - avoid that.
4045 getyx(stdscr, y, x);
4047 if (x >= col + (COLS / 2) - 2)
4049 } while (--count > 0);
4054 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
4056 const int height = 16;
4057 int row = 2 + (n % height);
4058 int col = (n / height) * COLS / 2;
4060 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4061 while (--repeat >= 0) {
4067 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
4070 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4071 /* display the wide-ACS character set */
4077 /*#define BOTH2(name) #name, &(name) */
4078 #define BOTH2(name) #name, MERGE_ATTR(name)
4082 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4086 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
4087 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
4088 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
4089 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
4091 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
4092 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
4093 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
4094 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
4096 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4097 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4099 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4100 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4101 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4102 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4104 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4105 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4106 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4107 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4108 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4109 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4110 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4111 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4114 #ifdef CURSES_WACS_ARRAY
4115 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4116 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4117 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4119 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4120 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4121 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4122 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4123 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4124 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4130 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4131 /* display the wide-ACS character set */
4137 /*#define BOTH2(name) #name, &(name) */
4138 #define BOTH2(name) #name, MERGE_ATTR(name)
4142 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4146 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4147 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4148 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4149 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4151 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4152 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4153 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4154 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4156 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4157 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4159 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4160 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4161 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4162 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4164 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4165 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4166 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4167 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4168 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4169 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4170 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4171 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4172 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4174 #ifdef CURSES_WACS_ARRAY
4175 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4176 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4177 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4179 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4180 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4181 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4182 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4183 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4184 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4191 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4192 /* display the wide-ACS character set */
4198 /*#define BOTH2(name) #name, &(name) */
4199 #define BOTH2(name) #name, MERGE_ATTR(name)
4203 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4207 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4208 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4209 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4210 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4212 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4213 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4214 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4215 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4217 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4218 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4220 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4221 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4222 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4223 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4225 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4226 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4227 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4228 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4229 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4230 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4231 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4232 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4233 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4235 #ifdef CURSES_WACS_ARRAY
4236 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4237 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4238 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4240 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4241 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4242 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4243 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4244 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4245 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4252 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4255 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4262 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4267 MERGE_ATTR(0, WACS_VLINE),
4268 MERGE_ATTR(1, WACS_VLINE),
4269 MERGE_ATTR(2, WACS_HLINE),
4270 MERGE_ATTR(3, WACS_HLINE),
4271 MERGE_ATTR(4, WACS_ULCORNER),
4272 MERGE_ATTR(5, WACS_URCORNER),
4273 MERGE_ATTR(6, WACS_LLCORNER),
4274 MERGE_ATTR(7, WACS_LRCORNER));
4276 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4277 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4278 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4279 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4280 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4281 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4282 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4289 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4291 const int height = 16;
4292 int row = 2 + (n % height);
4293 int col = (n / height) * COLS / 2;
4296 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4297 (void) attr_set(attr, pair, 0);
4298 _nc_STRNCPY(temp, code, 20);
4300 (void) attr_set(A_NORMAL, 0, 0);
4304 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4307 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4314 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4318 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4319 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4320 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4321 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4323 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4324 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4325 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4326 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4328 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4329 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4331 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4332 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4333 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4334 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4336 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4337 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4338 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4339 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4340 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4341 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4342 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4343 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4344 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4345 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4346 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4347 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4349 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4350 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4351 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4352 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4353 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4354 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4358 /* display the wide-ACS character set */
4360 x_acs_test(bool recur GCC_UNUSED)
4366 unsigned pagesize = 32;
4367 attr_t attr = WA_NORMAL;
4368 int fg = COLOR_BLACK;
4369 int bg = COLOR_BLACK;
4370 unsigned at_code = 0;
4371 NCURSES_PAIRS_T pair = 0;
4372 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4373 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4374 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4376 bool pending_code = FALSE;
4385 ToggleAcs(last_show_wacs, show_wacs_chars);
4389 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4394 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4398 if (pagesize == 32) {
4405 ToggleAcs(last_show_wacs, show_wbox_chars);
4408 ToggleAcs(last_show_wacs, show_utf8_chars);
4411 pending_code = !pending_code;
4413 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4414 } else if (at_page[0] != '\0') {
4415 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%x", digit);
4419 if (pending_code && isxdigit(c)) {
4420 size_t len = strlen(at_page);
4421 if (len && at_page[0] == '0') {
4422 memmove(at_page, at_page + 1, len--);
4424 if (len < sizeof(at_page) - 1) {
4425 at_page[len++] = (char) c;
4426 at_page[len] = '\0';
4428 } else if (pending_code
4429 && (c == '\b' || c == KEY_BACKSPACE || c == KEY_DC)) {
4430 size_t len = strlen(at_page);
4432 at_page[--len] = '\0';
4433 } else if (c < 256 && isdigit(c)) {
4434 digit = (unsigned) (c - '0');
4436 } else if (c == '+') {
4438 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4440 } else if (c == '-' && digit > 0) {
4442 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x",
4445 } else if (c == '>' && repeat < (COLS / 4)) {
4447 } else if (c == '<' && repeat > 1) {
4449 } else if (c == '_') {
4450 space = (space == ' ') ? '_' : ' ';
4452 } else if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)
4453 || cycle_colors(c, &fg, &bg, &pair)) {
4454 if (last_show_wacs != 0)
4462 if (pagesize != 32) {
4463 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4464 } else if (last_show_wacs != 0) {
4465 last_show_wacs(repeat, attr, pair);
4467 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4470 MvPrintw(LINES - 4, 0,
4471 "Select: a/d/t WACS, w=%d/page, @",
4474 pending_code ? at_page : "page");
4475 addstr(", x=box, u UTF-8, ^L repaint");
4476 MvPrintw(LINES - 3, 2,
4477 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4479 MvPrintw(LINES - 2, 2,
4480 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4481 my_list[at_code].name,
4484 MvPrintw(LINES - 2, 2,
4485 "v/V cycles through video attributes (%s).",
4486 my_list[at_code].name);
4489 } while (!isQuit(c = Getchar(), TRUE));
4500 * Graphic-rendition test (adapted from vttest)
4503 sgr_attr_test(bool recur GCC_UNUSED)
4507 for (pass = 0; pass < 2; pass++) {
4508 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4510 /* Use non-default colors if possible to exercise bce a little */
4512 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4513 normal |= (chtype) COLOR_PAIR(1);
4517 MvPrintw(1, 20, "Graphic rendition test pattern:");
4519 MvPrintw(4, 1, "vanilla");
4521 #define set_sgr(mask) bkgdset((normal^(mask)));
4523 MvPrintw(4, 40, "bold");
4525 set_sgr(A_UNDERLINE);
4526 MvPrintw(6, 6, "underline");
4528 set_sgr(A_BOLD | A_UNDERLINE);
4529 MvPrintw(6, 45, "bold underline");
4532 MvPrintw(8, 1, "blink");
4534 set_sgr(A_BLINK | A_BOLD);
4535 MvPrintw(8, 40, "bold blink");
4537 set_sgr(A_UNDERLINE | A_BLINK);
4538 MvPrintw(10, 6, "underline blink");
4540 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4541 MvPrintw(10, 45, "bold underline blink");
4544 MvPrintw(12, 1, "negative");
4546 set_sgr(A_BOLD | A_REVERSE);
4547 MvPrintw(12, 40, "bold negative");
4549 set_sgr(A_UNDERLINE | A_REVERSE);
4550 MvPrintw(14, 6, "underline negative");
4552 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4553 MvPrintw(14, 45, "bold underline negative");
4555 set_sgr(A_BLINK | A_REVERSE);
4556 MvPrintw(16, 1, "blink negative");
4558 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4559 MvPrintw(16, 40, "bold blink negative");
4561 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4562 MvPrintw(18, 6, "underline blink negative");
4564 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4565 MvPrintw(18, 45, "bold underline blink negative");
4568 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4574 bkgdset(A_NORMAL | BLANK);
4580 /****************************************************************************
4582 * Windows and scrolling tester.
4584 ****************************************************************************/
4586 #define BOTLINES 4 /* number of line stolen from screen bottom */
4592 #define FRAME struct frame
4601 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4602 #if (NCURSES_VERSION_PATCH < 20070331)
4603 #define is_keypad(win) (win)->_use_keypad
4604 #define is_scrollok(win) (win)->_scroll
4607 #define is_keypad(win) FALSE
4608 #define is_scrollok(win) FALSE
4612 frame_win(FRAME * curp)
4614 return (curp != 0) ? curp->wind : stdscr;
4617 /* We need to know if these flags are actually set, so don't look in FRAME.
4618 * These names are known to work with SVr4 curses as well as ncurses. The
4619 * _use_keypad name does not work with Solaris 8.
4622 HaveKeypad(FRAME * curp)
4624 WINDOW *win = frame_win(curp);
4626 return is_keypad(win);
4630 HaveScroll(FRAME * curp)
4632 WINDOW *win = frame_win(curp);
4634 return is_scrollok(win);
4638 newwin_legend(FRAME * curp)
4640 #define DATA(num, name) { name, num }
4641 static const struct {
4645 DATA(0, "^C = create window"),
4646 DATA(0, "^N = next window"),
4647 DATA(0, "^P = previous window"),
4648 DATA(0, "^F = scroll forward"),
4649 DATA(0, "^B = scroll backward"),
4650 DATA(1, "^K = keypad(%s)"),
4651 DATA(2, "^S = scrollok(%s)"),
4652 DATA(0, "^W = save window"),
4653 DATA(0, "^R = restore window"),
4655 DATA(0, "^X = resize"),
4657 DATA(3, "^Q%s = exit")
4661 bool do_keypad = HaveKeypad(curp);
4662 bool do_scroll = HaveScroll(curp);
4667 for (n = 0; n < SIZEOF(legend); n++) {
4670 switch (legend[n].code) {
4672 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4675 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4676 legend[n].msg, do_keypad ? "yes" : "no");
4679 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4680 legend[n].msg, do_scroll ? "yes" : "no");
4683 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4684 legend[n].msg, do_keypad ? "/ESC" : "");
4687 x = getcurx(stdscr);
4688 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4695 transient(FRAME * curp, NCURSES_CONST char *msg)
4697 newwin_legend(curp);
4699 MvAddStr(LINES - 1, 0, msg);
4705 printw("%s characters are echoed, window should %sscroll.",
4706 HaveKeypad(curp) ? "Non-arrow" : "All other",
4707 HaveScroll(curp) ? "" : "not ");
4712 newwin_report(FRAME * curp)
4713 /* report on the cursor's current position, then restore it */
4715 WINDOW *win = frame_win(curp);
4719 transient(curp, (char *) 0);
4721 move(LINES - 1, COLS - 17);
4722 printw("Y = %2d X = %2d", y, x);
4730 selectcell(int uli, int ulj, int lri, int lrj)
4731 /* arrows keys move cursor, return location at current on non-arrow key */
4733 static pair res; /* result cell */
4734 int si = lri - uli + 1; /* depth of the select area */
4735 int sj = lrj - ulj + 1; /* width of the select area */
4736 int i = 0, j = 0; /* offsets into the select area */
4741 move(uli + i, ulj + j);
4742 newwin_report((FRAME *) 0);
4744 switch (Getchar()) {
4758 return ((pair *) 0);
4759 #ifdef NCURSES_MOUSE_VERSION
4765 if (event.y > uli && event.x > ulj) {
4786 outerbox(pair ul, pair lr, bool onoff)
4787 /* draw or erase a box *outside* the given pair of corners */
4789 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4790 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4791 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4792 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4793 move(ul.y - 1, ul.x);
4794 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4795 move(ul.y, ul.x - 1);
4796 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4797 move(lr.y + 1, ul.x);
4798 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4799 move(ul.y, lr.x + 1);
4800 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4805 /* Ask user for a window definition */
4812 addstr("Use arrows to move cursor, anything else to mark corner 1");
4814 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4815 return ((WINDOW *) 0);
4816 memcpy(&ul, tmp, sizeof(pair));
4817 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4820 addstr("Use arrows to move cursor, anything else to mark corner 2");
4822 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4824 return ((WINDOW *) 0);
4825 memcpy(&lr, tmp, sizeof(pair));
4827 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4829 outerbox(ul, lr, TRUE);
4841 newwin_move(FRAME * curp, int dy, int dx)
4843 WINDOW *win = frame_win(curp);
4847 getyx(win, cur_y, cur_x);
4848 getmaxyx(win, max_y, max_x);
4849 if ((cur_x += dx) < 0)
4851 else if (cur_x >= max_x)
4853 if ((cur_y += dy) < 0)
4855 else if (cur_y >= max_y)
4857 wmove(win, cur_y, cur_x);
4861 delete_framed(FRAME * fp, bool showit)
4866 fp->last->next = fp->next;
4867 fp->next->last = fp->last;
4875 np = (fp == fp->next) ? NULL : fp->next;
4882 scroll_test(bool recur GCC_UNUSED)
4883 /* Demonstrate windows */
4886 FRAME *current = (FRAME *) 0, *neww;
4888 #if HAVE_PUTWIN && HAVE_GETWIN
4892 #define DUMPFILE "screendump"
4894 #ifdef NCURSES_MOUSE_VERSION
4895 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4900 transient((FRAME *) 0, (char *) 0);
4903 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4904 failed("scroll_test");
4907 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4908 failed("scroll_test");
4913 if (current == 0) { /* First element, */
4914 neww->next = neww; /* so point it at itself */
4917 neww->next = current->next;
4918 neww->last = current;
4919 neww->last->next = neww;
4920 neww->next->last = neww;
4923 /* SVr4 curses sets the keypad on all newly-created windows to
4924 * false. Someone reported that PDCurses makes new windows inherit
4925 * this flag. Remove the following 'keypad()' call to test this
4927 keypad(current->wind, TRUE);
4928 current->do_keypad = HaveKeypad(current);
4929 current->do_scroll = HaveScroll(current);
4932 case CTRL('N'): /* go to next window */
4934 current = current->next;
4937 case CTRL('P'): /* go to previous window */
4939 current = current->last;
4942 case CTRL('F'): /* scroll current window forward */
4944 wscrl(frame_win(current), 1);
4947 case CTRL('B'): /* scroll current window backwards */
4949 wscrl(frame_win(current), -1);
4952 case CTRL('K'): /* toggle keypad mode for current */
4954 current->do_keypad = !current->do_keypad;
4955 keypad(current->wind, current->do_keypad);
4961 current->do_scroll = !current->do_scroll;
4962 scrollok(current->wind, current->do_scroll);
4966 #if HAVE_PUTWIN && HAVE_GETWIN
4967 case CTRL('W'): /* save and delete window */
4968 if ((current != 0) && (current == current->next)) {
4969 transient(current, "Will not save/delete ONLY window");
4971 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4972 transient(current, "Can't open screen dump file");
4974 int rc = putwin(frame_win(current), fp);
4978 current = delete_framed(current, TRUE);
4980 transient(current, "Can't write screen dump file");
4985 case CTRL('R'): /* restore window */
4986 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4987 transient(current, "Can't open screen dump file");
4989 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4991 neww->next = current ? current->next : 0;
4992 neww->last = current;
4993 if (neww->last != 0)
4994 neww->last->next = neww;
4995 if (neww->next != 0)
4996 neww->next->last = neww;
4998 neww->wind = getwin(fp);
5000 wrefresh(neww->wind);
5002 failed("scroll_test");
5010 case CTRL('X'): /* resize window */
5017 addstr("Use arrows to move cursor, anything else to mark new corner");
5020 getbegyx(current->wind, ul.y, ul.x);
5022 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
5023 if (tmp == (pair *) 0) {
5028 getmaxyx(current->wind, lr.y, lr.x);
5031 outerbox(ul, lr, FALSE);
5032 wnoutrefresh(stdscr);
5034 /* strictly cosmetic hack for the test */
5035 getmaxyx(current->wind, my, mx);
5036 if (my > tmp->y - ul.y) {
5037 getyx(current->wind, lr.y, lr.x);
5038 wmove(current->wind, tmp->y - ul.y + 1, 0);
5039 wclrtobot(current->wind);
5040 wmove(current->wind, lr.y, lr.x);
5042 if (mx > tmp->x - ul.x) {
5044 for (i = 0; i < my; i++) {
5045 wmove(current->wind, i, tmp->x - ul.x + 1);
5046 wclrtoeol(current->wind);
5049 wnoutrefresh(current->wind);
5051 memcpy(&lr, tmp, sizeof(pair));
5052 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
5054 getbegyx(current->wind, ul.y, ul.x);
5055 getmaxyx(current->wind, lr.y, lr.x);
5058 outerbox(ul, lr, TRUE);
5059 wnoutrefresh(stdscr);
5061 wnoutrefresh(current->wind);
5067 #endif /* HAVE_WRESIZE */
5070 newwin_move(current, -1, 0);
5073 newwin_move(current, 1, 0);
5076 newwin_move(current, 0, -1);
5079 newwin_move(current, 0, 1);
5087 getyx(frame_win(current), y, x);
5091 x = getmaxx(frame_win(current)) - 1;
5093 (void) mvwdelch(frame_win(current), y, x);
5103 waddch(current->wind, (chtype) c);
5108 newwin_report(current);
5109 usescr = frame_win(current);
5112 (!isQuit(c = wGetchar(usescr), TRUE)
5116 while (current != 0)
5117 current = delete_framed(current, FALSE);
5119 scrollok(stdscr, TRUE); /* reset to driver's default */
5120 #ifdef NCURSES_MOUSE_VERSION
5121 mousemask(0, (mmask_t *) 0);
5129 /****************************************************************************
5133 ****************************************************************************/
5136 static int nap_msec = 1;
5138 static NCURSES_CONST char *mod[] =
5148 /*+-------------------------------------------------------------------------
5150 --------------------------------------------------------------------------*/
5152 wait_a_while(int msec GCC_UNUSED)
5162 else if (msec > 1000)
5163 sleep((unsigned) msec / 1000);
5167 } /* end of wait_a_while */
5169 /*+-------------------------------------------------------------------------
5171 --------------------------------------------------------------------------*/
5173 saywhat(NCURSES_CONST char *text)
5175 wmove(stdscr, LINES - 1, 0);
5177 if (text != 0 && *text != '\0') {
5178 waddstr(stdscr, text);
5179 waddstr(stdscr, "; ");
5181 waddstr(stdscr, "press any key to continue");
5182 } /* end of saywhat */
5184 /*+-------------------------------------------------------------------------
5185 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
5186 --------------------------------------------------------------------------*/
5188 mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx)
5193 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
5194 if ((pan = new_panel(win)) == 0) {
5196 } else if (UseColors) {
5197 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) ((color == COLOR_BLUE)
5200 NCURSES_COLOR_T bg = color;
5202 init_pair(color, fg, bg);
5203 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
5205 wbkgdset(win, A_BOLD | ' ');
5209 } /* end of mkpanel */
5211 /*+-------------------------------------------------------------------------
5213 --------------------------------------------------------------------------*/
5217 WINDOW *win = panel_window(pan);
5220 } /* end of rmpanel */
5222 /*+-------------------------------------------------------------------------
5224 --------------------------------------------------------------------------*/
5230 } /* end of pflush */
5232 /*+-------------------------------------------------------------------------
5234 --------------------------------------------------------------------------*/
5236 init_panel(WINDOW *win)
5240 for (y = 0; y < LINES - 1; y++) {
5241 for (x = 0; x < COLS; x++)
5242 wprintw(win, "%d", (y + x) % 10);
5247 fill_panel(PANEL *pan)
5249 WINDOW *win = panel_window(pan);
5250 const char *userptr = (const char *) panel_userptr(pan);
5251 int num = (userptr && *userptr) ? userptr[1] : '?';
5255 wprintw(win, "-pan%c-", num);
5258 for (y = 2; y < getmaxy(win) - 1; y++) {
5259 for (x = 1; x < getmaxx(win) - 1; x++) {
5261 waddch(win, UChar(num));
5266 #if USE_WIDEC_SUPPORT
5268 init_wide_panel(WINDOW *win)
5273 for (digit = 0; digit < 10; ++digit)
5274 make_fullwidth_digit(&temp[digit], digit);
5278 getyx(stdscr, y, x);
5279 digit = (y + x / 2) % 10;
5280 } while (wadd_wch(win, &temp[digit]) != ERR);
5284 fill_wide_panel(PANEL *pan)
5286 WINDOW *win = panel_window(pan);
5287 const char *userptr = (const char *) panel_userptr(pan);
5288 int num = (userptr && *userptr) ? userptr[1] : '?';
5292 wprintw(win, "-pan%c-", num);
5295 for (y = 2; y < getmaxy(win) - 1; y++) {
5296 for (x = 1; x < getmaxx(win) - 1; x++) {
5298 waddch(win, UChar(num));
5304 #define MAX_PANELS 5
5307 canned_panel(PANEL *px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
5309 int which = cmd[1] - '0';
5314 hide_panel(px[which]);
5317 show_panel(px[which]);
5320 top_panel(px[which]);
5323 bottom_panel(px[which]);
5330 wait_a_while(nap_msec);
5334 demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
5338 PANEL *px[MAX_PANELS + 1];
5340 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5344 for (count = 0; count < 5; count++) {
5345 px[1] = mkpanel(COLOR_RED,
5350 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
5352 px[2] = mkpanel(COLOR_GREEN,
5357 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
5359 px[3] = mkpanel(COLOR_YELLOW,
5364 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
5366 px[4] = mkpanel(COLOR_BLUE,
5371 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
5373 px[5] = mkpanel(COLOR_MAGENTA,
5378 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
5390 wait_a_while(nap_msec);
5392 saywhat("h3 s1 s2 s4 s5");
5393 move_panel(px[1], 0, 0);
5400 wait_a_while(nap_msec);
5402 canned_panel(px, "s1");
5403 canned_panel(px, "s2");
5406 move_panel(px[2], LINES / 3 + 1, COLS / 8);
5408 wait_a_while(nap_msec);
5410 canned_panel(px, "s3");
5413 move_panel(px[3], LINES / 4 + 1, COLS / 15);
5415 wait_a_while(nap_msec);
5417 canned_panel(px, "b3");
5418 canned_panel(px, "s4");
5419 canned_panel(px, "s5");
5420 canned_panel(px, "t3");
5421 canned_panel(px, "t1");
5422 canned_panel(px, "t2");
5423 canned_panel(px, "t3");
5424 canned_panel(px, "t4");
5426 for (itmp = 0; itmp < 6; itmp++) {
5427 WINDOW *w4 = panel_window(px[4]);
5428 WINDOW *w5 = panel_window(px[5]);
5431 wmove(w4, LINES / 8, 1);
5432 waddstr(w4, mod[itmp]);
5433 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5434 wmove(w5, LINES / 6, 1);
5435 waddstr(w5, mod[itmp]);
5437 wait_a_while(nap_msec);
5440 wmove(w4, LINES / 6, 1);
5441 waddstr(w4, mod[itmp]);
5442 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
5443 wmove(w5, LINES / 8, 1);
5444 waddstr(w5, mod[itmp]);
5446 wait_a_while(nap_msec);
5450 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5452 wait_a_while(nap_msec);
5454 canned_panel(px, "t5");
5455 canned_panel(px, "t2");
5456 canned_panel(px, "t1");
5457 canned_panel(px, "d2");
5458 canned_panel(px, "h3");
5459 canned_panel(px, "d1");
5460 canned_panel(px, "d4");
5461 canned_panel(px, "d5");
5462 canned_panel(px, "d3");
5464 wait_a_while(nap_msec);
5477 panel_test(bool recur GCC_UNUSED)
5479 return demo_panels(init_panel, fill_panel);
5483 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
5485 x_panel_test(bool recur GCC_UNUSED)
5487 return demo_panels(init_wide_panel, fill_wide_panel);
5490 #endif /* USE_LIBPANEL */
5492 /****************************************************************************
5496 ****************************************************************************/
5500 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
5501 * though we can rely on negative x/y values to stop the macro.
5504 do_h_line(int y, int x, chtype c, int to)
5507 MvHLine(y, x, c, (to) - (x));
5511 do_v_line(int y, int x, chtype c, int to)
5514 MvVLine(y, x, c, (to) - (y));
5519 static bool pending_pan = FALSE;
5520 static bool show_panner_legend = TRUE;
5523 panner_legend(int line)
5525 static const char *const legend[] =
5527 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
5528 "Use +,- (or j,k) to grow/shrink the panner vertically.",
5529 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
5530 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
5532 int n = ((int) SIZEOF(legend) - (LINES - line));
5534 if (move(line, 0) != ERR) {
5535 if (show_panner_legend)
5536 printw("%s", legend[n]);
5538 return show_panner_legend;
5545 panner_h_cleanup(int from_y, int from_x, int to_x)
5547 if (!panner_legend(from_y))
5548 do_h_line(from_y, from_x, ' ', to_x);
5552 panner_v_cleanup(int from_y, int from_x, int to_y)
5554 if (!panner_legend(from_y))
5555 do_v_line(from_y, from_x, ' ', to_y);
5559 fill_pad(WINDOW *panpad, bool pan_lines, bool colored)
5562 unsigned gridcount = 0;
5566 fill = (chtype) COLOR_PAIR(1);
5569 wmove(panpad, 0, 0);
5570 for (y = 0; y < getmaxy(panpad); y++) {
5571 for (x = 0; x < getmaxx(panpad); x++) {
5572 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
5573 if (y == 0 && x == 0)
5574 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
5576 waddch(panpad, pan_lines ? ACS_TTEE : '+');
5577 else if (y == 0 || x == 0)
5578 waddch(panpad, pan_lines ? ACS_LTEE : '+');
5580 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
5581 (int) (gridcount++ % 26)) | fill);
5582 } else if (y % GRIDSIZE == 0)
5583 waddch(panpad, pan_lines ? ACS_HLINE : '-');
5584 else if (x % GRIDSIZE == 0)
5585 waddch(panpad, pan_lines ? ACS_VLINE : '|');
5587 waddch(panpad, ' ');
5594 int top_x, int top_y, int porty, int portx,
5595 int (*pgetc) (WINDOW *),
5598 #if HAVE_GETTIMEOFDAY
5599 struct timeval before, after;
5602 bool pan_lines = FALSE;
5603 bool scrollers = TRUE;
5606 int pxmax, pymax, lowend, highend, c;
5608 getmaxyx(pad, pymax, pxmax);
5609 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5613 #ifdef NCURSES_VERSION
5615 * During shell-out, the user may have resized the window. Adjust
5616 * the port size of the pad to accommodate this. Ncurses automatically
5617 * resizes all of the normal windows to fit on the new screen.
5634 if (c == HELP_KEY_1)
5635 show_panner_legend = !show_panner_legend;
5636 panner_legend(LINES - 4);
5637 panner_legend(LINES - 3);
5638 panner_legend(LINES - 2);
5639 panner_legend(LINES - 1);
5642 pan_lines = !pan_lines;
5643 fill_pad(pad, pan_lines, colored);
5644 pending_pan = FALSE;
5647 #if HAVE_GETTIMEOFDAY
5651 panner_legend(LINES - 1);
5655 scrollers = !scrollers;
5658 /* Move the top-left corner of the pad, keeping the bottom-right
5661 case 'h': /* increase-columns: move left edge to left */
5665 panner_v_cleanup(top_y, top_x, porty);
5670 case 'j': /* decrease-lines: move top-edge down */
5674 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5679 case 'k': /* increase-lines: move top-edge up */
5684 panner_h_cleanup(top_y, top_x, portx);
5688 case 'l': /* decrease-columns: move left-edge to right */
5692 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5697 /* Move the bottom-right corner of the pad, keeping the top-left
5700 case KEY_IC: /* increase-columns: move right-edge to right */
5701 if (portx >= pxmax || portx >= COLS)
5704 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5709 case KEY_IL: /* increase-lines: move bottom-edge down */
5710 if (porty >= pymax || porty >= LINES)
5713 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5718 case KEY_DC: /* decrease-columns: move bottom edge up */
5723 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5727 case KEY_DL: /* decrease-lines */
5732 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5736 case KEY_LEFT: /* pan leftwards */
5743 case KEY_RIGHT: /* pan rightwards */
5744 if (basex + portx - (pymax > porty) < pxmax)
5750 case KEY_UP: /* pan upwards */
5757 case KEY_DOWN: /* pan downwards */
5758 if (basey + porty - (pxmax > portx) < pymax)
5773 basey = pymax - porty;
5783 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5784 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5785 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5787 if (scrollers && (pxmax > portx - 1)) {
5788 int length = (portx - top_x - 1);
5789 float ratio = ((float) length) / ((float) pxmax);
5791 lowend = (int) ((float) top_x + ((float) basex * ratio));
5792 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5794 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5795 if (highend < portx) {
5797 do_h_line(porty - 1, lowend, ' ', highend + 1);
5799 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5802 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5804 if (scrollers && (pymax > porty - 1)) {
5805 int length = (porty - top_y - 1);
5806 float ratio = ((float) length) / ((float) pymax);
5808 lowend = (int) ((float) top_y + ((float) basey * ratio));
5809 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5811 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5812 if (highend < porty) {
5814 do_v_line(lowend, portx - 1, ' ', highend + 1);
5816 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5819 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5821 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5822 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5823 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5826 #if HAVE_GETTIMEOFDAY
5827 gettimeofday(&before, 0);
5829 wnoutrefresh(stdscr);
5834 porty - (pxmax > portx) - 1,
5835 portx - (pymax > porty) - 1);
5838 #if HAVE_GETTIMEOFDAY
5839 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5842 gettimeofday(&after, 0);
5843 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5844 move(LINES - 1, COLS - 12);
5845 printw("Secs: %2.03f", elapsed);
5852 ((c = pgetc(pad)) != KEY_EXIT);
5854 scrollok(stdscr, TRUE); /* reset to driver's default */
5858 padgetch(WINDOW *win)
5863 if ((pending_pan = (count > 0)) != FALSE) {
5865 pending_pan = (count != 0);
5869 switch (c = wGetchar(win)) {
5905 case ERR: /* FALLTHRU */
5911 if (c >= '0' && c <= '9') {
5912 count = count * 10 + (c - '0');
5926 #define PAD_HIGH 200
5927 #define PAD_WIDE 200
5930 pad_test(bool recur GCC_UNUSED)
5931 /* Demonstrate pads. */
5933 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5936 Cannot("cannot create requested pad");
5941 init_pair(1, COLOR_BLACK, COLOR_GREEN);
5942 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5943 wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' '));
5946 fill_pad(panpad, FALSE, TRUE);
5948 panner_legend(LINES - 4);
5949 panner_legend(LINES - 3);
5950 panner_legend(LINES - 2);
5951 panner_legend(LINES - 1);
5953 keypad(panpad, TRUE);
5955 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5956 * We'll still be able to widen it during a test, since that's required
5957 * for testing boundaries.
5959 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, TRUE);
5966 #endif /* HAVE_NEWPAD */
5968 /****************************************************************************
5970 * Tests from John Burnell's PDCurses tester
5972 ****************************************************************************/
5975 Continue(WINDOW *win)
5979 MvWAddStr(win, 10, 1, " Press any key to continue");
5985 flushinp_test(bool recur GCC_UNUSED)
5986 /* Input test, adapted from John Burnell's PDCurses tester */
5988 WINDOW *win = stdscr;
5989 int w, h, bx, by, sw, sh, i;
5994 getmaxyx(win, h, w);
5995 getbegyx(win, by, bx);
5998 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
6003 init_pair(2, COLOR_CYAN, COLOR_BLUE);
6004 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
6007 (void) wattrset(subWin, A_BOLD);
6008 box(subWin, ACS_VLINE, ACS_HLINE);
6009 MvWAddStr(subWin, 2, 1, "This is a subwindow");
6013 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
6014 * it only happened to "work" on SVr4 because that implementation does not
6015 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
6016 * test behavior, we're using 'cbreak()', which will allow a single
6017 * character to return without needing a newline. - T.Dickey 1997/10/11.
6020 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
6022 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
6023 MvWAddStr(win, 3, 1,
6024 "These should be discarded (not echoed) after the subwindow goes away.");
6027 for (i = 0; i < 5; i++) {
6028 MvWPrintw(subWin, 1, 1, "Time = %d", i);
6040 MvWAddStr(win, 2, 1,
6041 "If you were still typing when the window timer expired,");
6042 MvWAddStr(win, 3, 1,
6043 "or else you typed nothing at all while it was running,");
6044 MvWAddStr(win, 4, 1,
6045 "test was invalid. You'll see garbage or nothing at all. ");
6046 MvWAddStr(win, 6, 1, "Press a key");
6052 MvWAddStr(win, 12, 0,
6053 "If you see any key other than what you typed, flushinp() is broken.");
6062 "What you typed should now have been deleted; if not, wdelch() failed.");
6069 /****************************************************************************
6073 ****************************************************************************/
6081 menu_virtualize(int c)
6083 if (c == '\n' || c == KEY_EXIT)
6084 return (MAX_COMMAND + 1);
6086 return (REQ_SCR_ULINE);
6088 return (REQ_SCR_DLINE);
6089 else if (c == 'b' || c == KEY_NPAGE)
6090 return (REQ_SCR_UPAGE);
6091 else if (c == 'f' || c == KEY_PPAGE)
6092 return (REQ_SCR_DPAGE);
6093 else if (c == 'n' || c == KEY_DOWN)
6094 return (REQ_NEXT_ITEM);
6095 else if (c == 'p' || c == KEY_UP)
6096 return (REQ_PREV_ITEM);
6098 return (REQ_TOGGLE_ITEM);
6106 static CONST_MENUS char *animals[] =
6119 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6120 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6125 menu_test(bool recur GCC_UNUSED)
6128 ITEM *items[SIZEOF(animals)];
6130 CONST_MENUS char **ap;
6131 int mrows, mcols, c;
6134 #ifdef NCURSES_MOUSE_VERSION
6135 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6137 MvAddStr(0, 0, "This is the menu test:");
6138 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
6139 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
6141 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
6142 MvAddStr(5, 0, " Press return to exit.");
6145 for (ap = animals; *ap; ap++) {
6146 if ((*ip = new_item(*ap, "")) != 0)
6151 m = new_menu(items);
6153 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
6154 scale_menu(m, &mrows, &mcols);
6156 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6157 set_menu_win(m, menuwin);
6158 keypad(menuwin, TRUE);
6161 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6165 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
6166 if (c == E_NOT_POSTED)
6168 if (c == E_REQUEST_DENIED)
6173 MvPrintw(LINES - 2, 0,
6174 "You chose: %s\n", item_name(current_item(m)));
6175 (void) addstr("Press any key to continue...");
6182 for (ip = items; *ip; ip++)
6184 #ifdef NCURSES_MOUSE_VERSION
6185 mousemask(0, (mmask_t *) 0);
6191 #define T_TBL(name) { #name, name }
6197 T_TBL(TRACE_DISABLE),
6200 T_TBL(TRACE_UPDATE),
6202 T_TBL(TRACE_CHARPUT),
6203 T_TBL(TRACE_ORDINARY),
6205 T_TBL(TRACE_VIRTPUT),
6206 T_TBL(TRACE_IEVENT),
6208 T_TBL(TRACE_ICALLS),
6209 T_TBL(TRACE_CCALLS),
6210 T_TBL(TRACE_DATABASE),
6212 T_TBL(TRACE_MAXIMUM),
6219 tracetrace(unsigned tlevel)
6222 static size_t need = 12;
6226 for (n = 0; t_tbl[n].name != 0; n++)
6227 need += strlen(t_tbl[n].name) + 2;
6228 buf = typeMalloc(char, need);
6230 failed("tracetrace");
6232 _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
6234 _nc_STRCAT(buf, t_tbl[0].name, need);
6235 _nc_STRCAT(buf, ", ", need);
6237 for (n = 1; t_tbl[n].name != 0; n++)
6238 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
6239 _nc_STRCAT(buf, t_tbl[n].name, need);
6240 _nc_STRCAT(buf, ", ", need);
6243 if (buf[strlen(buf) - 2] == ',')
6244 buf[strlen(buf) - 2] = '\0';
6245 _nc_STRCAT(buf, "}", need);
6249 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
6253 run_trace_menu(MENU * m)
6259 bool changed = FALSE;
6260 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
6261 case E_UNKNOWN_COMMAND:
6264 items = menu_items(m);
6265 i = current_item(m);
6266 if (i == items[0]) {
6267 if (item_value(i)) {
6268 for (p = items + 1; *p != 0; p++)
6269 if (item_value(*p)) {
6270 set_item_value(*p, FALSE);
6275 for (p = items + 1; *p != 0; p++)
6276 if (item_value(*p)) {
6277 set_item_value(items[0], FALSE);
6289 trace_set(bool recur GCC_UNUSED)
6290 /* interactively set the trace level */
6293 ITEM *items[SIZEOF(t_tbl)];
6300 MvAddStr(0, 0, "Interactively set trace level:");
6301 MvAddStr(2, 0, " Press space bar to toggle a selection.");
6302 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
6303 MvAddStr(4, 0, " Press return to set the trace level.");
6304 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
6308 for (n = 0; t_tbl[n].name != 0; n++) {
6309 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
6315 m = new_menu(items);
6317 set_menu_format(m, 0, 2);
6318 scale_menu(m, &mrows, &mcols);
6320 menu_opts_off(m, O_ONEVALUE);
6321 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6322 set_menu_win(m, menuwin);
6323 keypad(menuwin, TRUE);
6326 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6330 for (ip = menu_items(m); *ip; ip++) {
6331 unsigned mask = t_tbl[item_index(*ip)].mask;
6333 set_item_value(*ip, _nc_tracing == 0);
6334 else if ((mask & _nc_tracing) == mask)
6335 set_item_value(*ip, TRUE);
6338 while (run_trace_menu(m))
6342 for (ip = menu_items(m); *ip; ip++)
6343 if (item_value(*ip))
6344 newtrace |= t_tbl[item_index(*ip)].mask;
6345 curses_trace(newtrace);
6346 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
6348 MvPrintw(LINES - 2, 0,
6349 "Trace level is %s\n", tracetrace(_nc_tracing));
6350 (void) addstr("Press any key to continue...");
6357 for (ip = items; *ip; ip++)
6363 #endif /* USE_LIBMENU */
6365 /****************************************************************************
6369 ****************************************************************************/
6372 make_label(int frow, int fcol, NCURSES_CONST char *label)
6374 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
6377 set_field_buffer(f, 0, label);
6378 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
6384 make_field(int frow, int fcol, int rows, int cols, bool secure)
6386 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
6389 set_field_back(f, A_UNDERLINE);
6390 set_field_userptr(f, (void *) 0);
6396 display_form(FORM *f)
6401 scale_form(f, &rows, &cols);
6403 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
6405 set_form_sub(f, derwin(w, rows, cols, 1, 2));
6408 if (post_form(f) != E_OK)
6416 WINDOW *w = form_win(f);
6417 WINDOW *s = form_sub(f);
6427 edit_secure(FIELD *me, int c)
6429 int rows, cols, frow, fcol, nrow, nbuf;
6431 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
6433 char *source = field_buffer(me, 1);
6434 size_t have = (source ? strlen(source) : 0) + 1;
6435 size_t need = 80 + have;
6436 char *temp = malloc(need);
6440 _nc_STRNCPY(temp, source ? source : "", have + 1);
6441 len = (size_t) (char *) field_userptr(me);
6443 if (isgraph(c) && (len + 1) < sizeof(temp)) {
6444 temp[len++] = (char) c;
6446 set_field_buffer(me, 1, temp);
6466 case REQ_RIGHT_CHAR:
6468 c = 0; /* we don't want to do inline editing */
6473 set_field_buffer(me, 1, temp);
6480 set_field_buffer(me, 1, temp);
6485 set_field_userptr(me, (void *) len);
6493 form_virtualize(FORM *f, WINDOW *w)
6496 static const struct {
6500 { CTRL('A'), REQ_NEXT_CHOICE },
6501 { CTRL('B'), REQ_PREV_WORD },
6502 { CTRL('C'), REQ_CLR_EOL },
6503 { CTRL('D'), REQ_DOWN_FIELD },
6504 { CTRL('E'), REQ_END_FIELD },
6505 { CTRL('F'), REQ_NEXT_PAGE },
6506 { CTRL('G'), REQ_DEL_WORD },
6507 { CTRL('H'), REQ_DEL_PREV },
6508 { CTRL('I'), REQ_INS_CHAR },
6509 { CTRL('K'), REQ_CLR_EOF },
6510 { CTRL('L'), REQ_LEFT_FIELD },
6511 { CTRL('M'), REQ_NEW_LINE },
6512 { CTRL('N'), REQ_NEXT_FIELD },
6513 { CTRL('O'), REQ_INS_LINE },
6514 { CTRL('P'), REQ_PREV_FIELD },
6515 { CTRL('R'), REQ_RIGHT_FIELD },
6516 { CTRL('S'), REQ_BEG_FIELD },
6517 { CTRL('U'), REQ_UP_FIELD },
6518 { CTRL('V'), REQ_DEL_CHAR },
6519 { CTRL('W'), REQ_NEXT_WORD },
6520 { CTRL('X'), REQ_CLR_FIELD },
6521 { CTRL('Y'), REQ_DEL_LINE },
6522 { CTRL('Z'), REQ_PREV_CHOICE },
6523 { ESCAPE, MAX_FORM_COMMAND + 1 },
6524 { KEY_BACKSPACE, REQ_DEL_PREV },
6525 { KEY_DOWN, REQ_DOWN_CHAR },
6526 { KEY_END, REQ_LAST_FIELD },
6527 { KEY_HOME, REQ_FIRST_FIELD },
6528 { KEY_LEFT, REQ_LEFT_CHAR },
6529 { KEY_LL, REQ_LAST_FIELD },
6530 { KEY_NEXT, REQ_NEXT_FIELD },
6531 { KEY_NPAGE, REQ_NEXT_PAGE },
6532 { KEY_PPAGE, REQ_PREV_PAGE },
6533 { KEY_PREVIOUS, REQ_PREV_FIELD },
6534 { KEY_RIGHT, REQ_RIGHT_CHAR },
6535 { KEY_UP, REQ_UP_CHAR },
6536 { QUIT, MAX_FORM_COMMAND + 1 }
6540 static int mode = REQ_INS_MODE;
6541 int c = wGetchar(w);
6542 FIELD *me = current_field(f);
6543 bool current = TRUE;
6545 if (c == CTRL(']')) {
6546 if (mode == REQ_INS_MODE) {
6547 mode = REQ_OVL_MODE;
6549 mode = REQ_INS_MODE;
6554 for (n = 0; n < SIZEOF(lookup); n++) {
6555 if (lookup[n].code == c) {
6556 c = lookup[n].result;
6561 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
6564 * Force the field that the user is typing into to be in reverse video,
6565 * while the other fields are shown underlined.
6580 case REQ_LEFT_FIELD:
6582 case REQ_RIGHT_CHAR:
6586 current = (c < KEY_MAX);
6590 c = edit_secure(me, c);
6591 set_field_back(me, A_REVERSE);
6593 c = edit_secure(me, c);
6594 set_field_back(me, A_UNDERLINE);
6600 my_form_driver(FORM *form, int c)
6602 if (c == (MAX_FORM_COMMAND + 1)
6603 && form_driver(form, REQ_VALIDATION) == E_OK)
6611 #ifdef NCURSES_VERSION
6612 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6613 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6615 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6616 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6620 * Allow a middle initial, optionally with a '.' to end it.
6623 FIELDCHECK_CB(mi_field_check)
6625 char *s = field_buffer(fld, 0);
6629 for (n = 0; s[n] != '\0'; ++n) {
6636 } else if (isspace(UChar(s[n]))) {
6641 if (!isspace(UChar(s[n])))
6647 /* force the form to display a leading capital */
6648 if (islower(UChar(s[0]))) {
6649 s[0] = (char) toupper(UChar(s[0]));
6650 set_field_buffer(fld, 0, s);
6656 CHAR_CHECK_CB(mi_char_check)
6658 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6662 * Passwords should be at least 6 characters.
6665 FIELDCHECK_CB(pw_field_check)
6667 char *s = field_buffer(fld, 0);
6670 for (n = 0; s[n] != '\0'; ++n) {
6671 if (isspace(UChar(s[n]))) {
6680 CHAR_CHECK_CB(pw_char_check)
6682 return (isgraph(ch) ? TRUE : FALSE);
6686 form_test(bool recur GCC_UNUSED)
6689 FIELD *f[12], *secure;
6690 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6691 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6695 #ifdef NCURSES_MOUSE_VERSION
6696 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6700 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6701 addstr("^N -- go to next field ^P -- go to previous field\n");
6702 addstr("Home -- go to first field End -- go to last field\n");
6703 addstr("^L -- go to field to left ^R -- go to field to right\n");
6704 addstr("^U -- move upward to field ^D -- move downward to field\n");
6705 addstr("^W -- go to next word ^B -- go to previous word\n");
6706 addstr("^S -- go to start of field ^E -- go to end of field\n");
6707 addstr("^H -- delete previous char ^Y -- delete line\n");
6708 addstr("^G -- delete current word ^C -- clear to end of line\n");
6709 addstr("^K -- clear to end of field ^X -- clear field\n");
6710 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6712 MvAddStr(4, 57, "Forms Entry Test");
6716 /* describe the form */
6717 memset(f, 0, sizeof(f));
6718 f[n++] = make_label(0, 15, "Sample Form");
6720 f[n++] = make_label(2, 0, "Last Name");
6721 f[n++] = make_field(3, 0, 1, 18, FALSE);
6722 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6724 f[n++] = make_label(2, 20, "First Name");
6725 f[n++] = make_field(3, 20, 1, 12, FALSE);
6726 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6728 f[n++] = make_label(2, 34, "Middle Name");
6729 f[n++] = make_field(3, 34, 1, 12, FALSE);
6730 set_field_type(f[n - 1], fty_middle);
6732 f[n++] = make_label(5, 0, "Comments");
6733 f[n++] = make_field(6, 0, 4, 46, FALSE);
6735 f[n++] = make_label(5, 20, "Password:");
6737 f[n++] = make_field(5, 30, 1, 9, TRUE);
6738 set_field_type(f[n - 1], fty_passwd);
6741 if ((form = new_form(f)) != 0) {
6749 nonl(); /* lets us read ^M's */
6751 switch (form_driver(form, c = form_virtualize(form, w))) {
6753 MvAddStr(5, 57, field_buffer(secure, 1));
6757 case E_UNKNOWN_COMMAND:
6758 finished = my_form_driver(form, c);
6770 for (c = 0; f[c] != 0; c++)
6772 free_fieldtype(fty_middle);
6773 free_fieldtype(fty_passwd);
6777 #ifdef NCURSES_MOUSE_VERSION
6778 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6782 #endif /* USE_LIBFORM */
6784 /****************************************************************************
6788 ****************************************************************************/
6790 #if HAVE_COPYWIN /* ...and overlay, overwrite */
6792 static const int overlap_HEAD = 1;
6793 static const int overlap_FOOT = 6;
6801 getmaxyx(stdscr, y, x);
6802 if (y < 23 || x < 80) {
6803 Cannot("The screen is too small for this test");
6806 int ymax = y - (overlap_HEAD + overlap_FOOT);
6807 int high = ymax / 5; /* equal-sized parts for cross */
6808 int xmax = x - 2; /* margin */
6809 int wide = (xmax / 5) & ~1;
6818 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6819 lmar = (xmax - (5 * wide)) / 2;
6822 result = newwin(3 * high, 3 * wide, tmar, lmar);
6824 result = newwin(3 * high, 3 * wide, tmar + 2 * high, lmar + 2 * wide);
6835 for (row = overlap_HEAD; row < LINES - overlap_FOOT; ++row) {
6842 move_overlap(int shift, WINDOW *win1)
6844 int ymax = getmaxy(stdscr) - (overlap_HEAD + overlap_FOOT);
6845 int high = ymax / 5; /* equal-sized parts for cross */
6847 int xmax1 = getmaxx(win1) + 1;
6848 int lmar1 = (COLS - (5 * (xmax1) / 3)) / 2;
6853 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6855 rc = mvwin(win1, tmar, lmar1 + shift);
6860 fillwin(WINDOW *win, char ch)
6865 getmaxyx(win, y1, x1);
6866 for (y = 0; y < y1; y++) {
6868 for (x = 0; x < x1; x++)
6869 waddch(win, UChar(ch));
6873 #define InCross(x,y, x1,y1) \
6874 (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3)) \
6875 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3))))
6878 crosswin(WINDOW *win, char ch)
6884 getmaxyx(win, y1, x1);
6885 for (y = 0; y < y1; y++) {
6886 for (x = 0; x < x1; x += xw) {
6887 if (InCross(x, y, x1, y1)) {
6889 waddch(win, UChar(ch));
6896 * Match "crosswin()", but using line-drawing characters. This could be done
6897 * a little simpler using box(), but the reason for this example is to test
6898 * hline/vline and addch with line-drawing vs the copy/overlay functions.
6901 crossbox(WINDOW *win)
6906 getmaxyx(win, y1, x1);
6911 mvwhline(win, 0, (xmax / 3), ACS_HLINE, (xmax / 3));
6912 mvwhline(win, ymax / 3, 0, ACS_HLINE, xmax);
6913 mvwhline(win, ((2 * ymax) / 3) - 1, 0, ACS_HLINE, xmax);
6914 mvwhline(win, y1 - 1, (xmax / 3), ACS_HLINE, (xmax / 3));
6916 mvwvline(win, (ymax / 3), 0, ACS_VLINE, (ymax / 3));
6917 mvwvline(win, 0, xmax / 3, ACS_VLINE, ymax);
6918 mvwvline(win, 0, ((2 * xmax) / 3) - 1, ACS_VLINE, ymax);
6919 mvwvline(win, (ymax / 3), x1 - 1, ACS_VLINE, (ymax / 3));
6921 mvwaddch(win, 0, (xmax / 3), ACS_ULCORNER);
6922 mvwaddch(win, 0, ((2 * xmax) / 3) - 1, ACS_URCORNER);
6923 mvwaddch(win, y1 - 1, (xmax / 3), ACS_LLCORNER);
6924 mvwaddch(win, y1 - 1, ((2 * xmax) / 3) - 1, ACS_LRCORNER);
6926 mvwaddch(win, (ymax / 3), 0, ACS_ULCORNER);
6927 mvwaddch(win, ((2 * ymax) / 3) - 1, 0, ACS_LLCORNER);
6928 mvwaddch(win, (ymax / 3), x1 - 1, ACS_URCORNER);
6929 mvwaddch(win, ((2 * ymax) / 3) - 1, x1 - 1, ACS_LRCORNER);
6931 mvwaddch(win, (ymax / 3), (xmax / 3), ACS_PLUS);
6932 mvwaddch(win, (ymax / 3), ((2 * xmax) / 3) - 1, ACS_PLUS);
6933 mvwaddch(win, ((2 * ymax) / 3) - 1, ((2 * xmax) / 3) - 1, ACS_PLUS);
6934 mvwaddch(win, ((2 * ymax) / 3) - 1, (xmax / 3), ACS_PLUS);
6945 #define OVERLAP_FLAVORS 6
6954 #define LimitFILL() UseColors ? 4 : 2
6957 otDRAW_text_cross = 0
6964 #define LimitDRAW() UseColors ? 5 : 3
6967 otCOPY_overwrite = 0
6973 #define LimitCOPY() 4
6976 overlap_helpitem(int state, int item, char *message)
6978 int row = (item / 2);
6979 int col = ((item % 2) ? COLS / 2 : 0);
6981 move(LINES - 6 + row, col);
6982 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6987 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6989 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
6991 switch ((otFILL) flavor) {
6993 (void) wattrset(win, A_NORMAL);
6996 (void) wattrset(win, A_BOLD);
6999 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
7000 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
7003 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
7004 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
7010 overlap_test_2_attr(WINDOW *win, int flavor, int col)
7012 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
7014 switch ((otDRAW) flavor) {
7015 case otDRAW_text_cross:
7018 case otDRAW_line_box:
7021 case otDRAW_line_cross:
7025 init_pair(cpair, COLOR_RED, COLOR_GREEN);
7026 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
7028 case otDRAW_reset_bg:
7029 wbkgdset(win, ' ' | A_NORMAL);
7035 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
7038 int limit[OVERLAP_FLAVORS];
7042 state += OVERLAP_FLAVORS;
7043 state = state % OVERLAP_FLAVORS;
7044 assert(state >= 0 && state < OVERLAP_FLAVORS);
7046 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
7049 const char *ths = col ? "B" : "A";
7050 const char *tht = col ? "A" : "B";
7052 switch ((otBASE) row) {
7053 case otBASE_refresh:
7056 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7057 "refresh %s, then %s, then doupdate.", ths, tht);
7060 limit[row] = LimitFILL();
7061 flavors[row] %= limit[row];
7062 overlap_test_1_attr(stdscr, flavors[row], col);
7063 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7064 "fill window %s with letter %s.", ths, ths);
7067 limit[row] = LimitDRAW();
7068 flavors[row] %= limit[row];
7069 switch ((otDRAW) flavors[row]) {
7070 case otDRAW_text_cross:
7071 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7072 "cross text-pattern in window %s.", ths);
7074 case otDRAW_line_box:
7075 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7076 "draw line-box in window %s.", ths);
7078 case otDRAW_line_cross:
7079 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7080 "draw line-cross in window %s.", ths);
7083 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7084 "set background of window %s.", ths);
7086 case otDRAW_reset_bg:
7087 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7088 "reset background of window %s.", ths);
7095 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7096 "clear window %s.", ths);
7099 limit[row] = LimitCOPY();
7100 flavors[row] %= limit[row];
7101 switch ((otCOPY) flavors[row]) {
7102 case otCOPY_overwrite:
7103 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7104 "overwrite %s onto %s.", ths, tht);
7107 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7108 "copywin(FALSE) %s onto %s.", ths, tht);
7111 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7112 "copywin(TRUE) %s onto %s.", ths, tht);
7114 case otCOPY_overlay:
7115 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7116 "overlay %s onto %s.", ths, tht);
7121 overlap_helpitem(state, item, msg);
7122 (void) wattrset(stdscr, A_NORMAL);
7123 wbkgdset(stdscr, ' ' | A_NORMAL);
7126 printw("^Q/ESC = terminate test. </> shift. Up/down/space select (row %d",
7128 if (limit[state] > 1)
7129 printw(" test %d:%d", 1 + flavors[state], limit[state]);
7137 overlap_test_0(WINDOW *a, WINDOW *b)
7147 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
7149 overlap_test_1_attr(a, flavor, col);
7151 (void) wattrset(a, A_NORMAL);
7155 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
7157 overlap_test_2_attr(a, flavor, col);
7158 switch ((otDRAW) flavor) {
7159 case otDRAW_text_cross:
7162 case otDRAW_line_box:
7165 case otDRAW_line_cross:
7169 /* done in overlap_test_2_attr */
7171 case otDRAW_reset_bg:
7172 /* done in overlap_test_2_attr */
7178 overlap_test_3(WINDOW *a)
7185 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
7187 switch ((otCOPY) flavor) {
7188 case otCOPY_overwrite:
7192 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
7195 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
7197 case otCOPY_overlay:
7203 /* test effects of overlapping windows */
7205 overlap_test(bool recur GCC_UNUSED)
7207 WINDOW *win1, *win2;
7209 int shift = 0, last_refresh = -1;
7210 int state, flavor[OVERLAP_FLAVORS];
7212 if ((win1 = make_overlap(0)) == 0) {
7214 } else if ((win2 = make_overlap(1)) == 0) {
7223 printw("Test wnoutrefresh() for two overlapping windows:");
7225 memset(flavor, 0, sizeof(flavor));
7226 state = overlap_help(0, flavor);
7228 while (!isQuit(ch = Getchar(), TRUE)) {
7230 case 'a': /* refresh window A first, then B */
7231 overlap_test_0(win1, win2);
7234 case 'b': /* refresh window B first, then A */
7235 overlap_test_0(win2, win1);
7238 case 'c': /* fill window A so it's visible */
7239 overlap_test_1(flavor[otBASE_fill], 0, win1, 'A');
7242 case 'd': /* fill window B so it's visible */
7243 overlap_test_1(flavor[otBASE_fill], 1, win2, 'B');
7246 case 'e': /* cross test pattern in window A */
7247 overlap_test_2(flavor[otBASE_draw], 0, win1, 'A');
7250 case 'f': /* cross test pattern in window A */
7251 overlap_test_2(flavor[otBASE_draw], 1, win2, 'B');
7254 case 'g': /* clear window A */
7255 overlap_test_3(win1);
7258 case 'h': /* clear window B */
7259 overlap_test_3(win2);
7262 case 'i': /* overwrite A onto B */
7263 overlap_test_4(flavor[otBASE_copy], win1, win2);
7266 case 'j': /* overwrite B onto A */
7267 overlap_test_4(flavor[otBASE_copy], win2, win1);
7272 state = overlap_help(state + 1, flavor);
7277 state = overlap_help(state - 1, flavor);
7282 state = overlap_help(state, flavor);
7286 state = overlap_help(state, flavor);
7311 if (move_overlap(shift, win1) != OK) {
7313 shift += (ch == '>') ? -1 : 1;
7314 } else if (last_refresh > 0) {
7316 wnoutrefresh(stdscr);
7317 if (last_refresh == 'a')
7318 overlap_test_0(win1, win2);
7320 overlap_test_0(win2, win1);
7336 #if USE_WIDEC_SUPPORT
7338 x_fillwin(WINDOW *win, wchar_t ch)
7343 getmaxyx(win, y1, x1);
7345 for (y = 0; y < y1; y++) {
7347 for (x = 0; x < x1; x++)
7348 waddnwstr(win, &ch, 1);
7353 x_crosswin(WINDOW *win, wchar_t ch)
7359 getmaxyx(win, y1, x1);
7360 for (y = 0; y < y1; y++) {
7361 for (x = 0; x < x1; x += xw) {
7362 if (InCross(x, y, x1, y1)) {
7364 waddnwstr(win, &ch, 1);
7371 x_overlap_test_1(int flavor, int col, WINDOW *a, wchar_t fill)
7373 overlap_test_1_attr(a, flavor, col);
7375 (void) wattrset(a, A_NORMAL);
7379 x_overlap_test_2(int flavor, int col, WINDOW *a, wchar_t fill)
7381 overlap_test_2_attr(a, flavor, col);
7382 switch ((otDRAW) flavor) {
7383 case otDRAW_text_cross:
7384 x_crosswin(a, fill);
7386 case otDRAW_line_box:
7389 case otDRAW_line_cross:
7393 /* done in overlap_test_2_attr */
7395 case otDRAW_reset_bg:
7396 /* done in overlap_test_2_attr */
7401 /* test effects of overlapping windows */
7403 x_overlap_test(bool recur GCC_UNUSED)
7405 const wchar_t WIDE_A = 0xff21;
7406 const wchar_t WIDE_B = 0xff22;
7407 WINDOW *win1, *win2;
7409 int shift = 0, last_refresh = -1;
7410 int state, flavor[OVERLAP_FLAVORS];
7412 if ((win1 = make_overlap(0)) == 0) {
7414 } else if ((win2 = make_overlap(1)) == 0) {
7423 printw("Test wnoutrefresh() for overlapping windows with double-cell characters:");
7425 memset(flavor, 0, sizeof(flavor));
7426 state = overlap_help(0, flavor);
7428 while (!isQuit(ch = Getchar(), TRUE)) {
7430 case 'a': /* refresh window A first, then B */
7431 overlap_test_0(win1, win2);
7434 case 'b': /* refresh window B first, then A */
7435 overlap_test_0(win2, win1);
7438 case 'c': /* fill window A so it's visible */
7439 x_overlap_test_1(flavor[otBASE_fill], 0, win1, WIDE_A);
7442 case 'd': /* fill window B so it's visible */
7443 x_overlap_test_1(flavor[otBASE_fill], 1, win2, WIDE_B);
7446 case 'e': /* cross test pattern in window A */
7447 x_overlap_test_2(flavor[otBASE_draw], 0, win1, WIDE_A);
7450 case 'f': /* cross test pattern in window A */
7451 x_overlap_test_2(flavor[otBASE_draw], 1, win2, WIDE_B);
7454 case 'g': /* clear window A */
7455 overlap_test_3(win1);
7458 case 'h': /* clear window B */
7459 overlap_test_3(win2);
7462 case 'i': /* overwrite A onto B */
7463 overlap_test_4(flavor[otBASE_copy], win1, win2);
7466 case 'j': /* overwrite B onto A */
7467 overlap_test_4(flavor[otBASE_copy], win2, win1);
7472 state = overlap_help(state + 1, flavor);
7477 state = overlap_help(state - 1, flavor);
7482 state = overlap_help(state, flavor);
7486 state = overlap_help(state, flavor);
7511 if (move_overlap(shift, win1) != OK) {
7513 shift += (ch == '>') ? -1 : 1;
7514 } else if (last_refresh > 0) {
7516 wnoutrefresh(stdscr);
7517 if (last_refresh == 'a')
7518 overlap_test_0(win1, win2);
7520 overlap_test_0(win2, win1);
7535 #endif /* USE_WIDEC_SUPPORT */
7537 #endif /* HAVE_COPYWIN */
7540 show_setting_name(const char *name)
7542 printw("%-25s ", name);
7546 show_string_setting(const char *name, const char *value)
7548 show_setting_name(name);
7550 printw("\"%s\"", value);
7560 show_number_setting(const char *name, int value)
7562 show_setting_name(name);
7564 printw("%d", value);
7567 printw("%d", value);
7574 show_boolean_setting(const char *name, int value)
7576 show_setting_name(name);
7578 printw("%s", value ? "TRUE" : "FALSE");
7581 printw("%d", value);
7588 settings_test(bool recur GCC_UNUSED)
7590 #if USE_WIDEC_SUPPORT
7595 show_string_setting("termname", termname());
7596 show_string_setting("longname", longname());
7597 show_number_setting("baudrate", baudrate());
7598 if (erasechar() > 0) {
7599 show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar()));
7600 show_string_setting("keyname(erasechar)", keyname(erasechar()));
7602 if (killchar() > 0) {
7603 show_string_setting("unctrl(killchar)", unctrl((chtype) killchar()));
7604 show_string_setting("keyname(killchar)", keyname(killchar()));
7606 #if USE_WIDEC_SUPPORT
7607 if (erasewchar(&ch) == OK) {
7608 show_string_setting("key_name(erasewchar)", key_name(ch));
7610 if (killwchar(&ch) == OK) {
7611 show_string_setting("key_name(killwchar)", key_name(ch));
7614 show_boolean_setting("has_ic", has_ic());
7615 show_boolean_setting("has_il", has_il());
7616 show_boolean_setting("has_colors", has_colors());
7617 #if HAVE_COLOR_CONTENT
7618 show_boolean_setting("can_change_color", can_change_color());
7626 /****************************************************************************
7630 ****************************************************************************/
7635 static const char *const tbl[] =
7637 "Usage: ncurses [options]"
7640 #ifdef NCURSES_VERSION
7641 ," -a f,b set default-colors (assumed white-on-black)"
7642 ," -d use default-colors if terminal supports them"
7645 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
7648 ," -e fmt specify format for soft-keys test (e)"
7651 ," -f rip-off footer line (can repeat)"
7652 ," -h rip-off header line (can repeat)"
7654 ," -m do not use colors"
7655 #if HAVE_COLOR_CONTENT
7656 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
7659 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
7661 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_WIN32)
7662 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
7665 ," -t mask specify default trace-level (may toggle with ^T)"
7667 #if HAVE_COLOR_CONTENT
7668 ," -x use xterm-compatible control for reading color palette"
7672 for (n = 0; n < SIZEOF(tbl); n++)
7673 fprintf(stderr, "%s\n", tbl[n]);
7674 ExitProgram(EXIT_FAILURE);
7678 set_terminal_modes(void)
7683 scrollok(stdscr, TRUE);
7684 idlok(stdscr, TRUE);
7685 keypad(stdscr, TRUE);
7690 announce_sig(int sig)
7692 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
7698 rip_footer(WINDOW *win, int cols)
7700 wbkgd(win, A_REVERSE);
7703 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
7709 rip_header(WINDOW *win, int cols)
7711 wbkgd(win, A_REVERSE);
7714 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
7718 #endif /* HAVE_RIPOFFLINE */
7723 #if USE_WIDEC_SUPPORT
7726 int (*narrow_func) (bool);
7727 int (*wide_func) (bool);
7731 #define BOTH(a) a, x_ ## a
7732 #define ONLY(a) a, NULL
7733 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7737 int (*narrow_func) (bool);
7743 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7746 static MyCmds cmds[] =
7748 CMDS(TRUE, BOTH(getch_test), 'a', "keyboard and mouse input test"),
7749 CMDS(TRUE, BOTH(attr_test), 'b', "character attribute test"),
7750 CMDS(TRUE, BOTH(color_test), 'c', "color test pattern"),
7751 #if HAVE_COLOR_CONTENT
7752 CMDS(FALSE, ONLY(color_edit), 'd', "edit RGB color values"),
7755 CMDS(TRUE, BOTH(slk_test), 'e', "exercise soft keys"),
7757 CMDS(TRUE, BOTH(acs_test), 'f', "display ACS characters"),
7758 CMDS(TRUE, ONLY(scroll_test), 'g', "display windows and scrolling"),
7759 CMDS(TRUE, ONLY(flushinp_test), 'i', "test flushinp()"),
7760 CMDS(TRUE, ONLY(sgr_attr_test), 'k', "display character attributes"),
7762 CMDS(TRUE, ONLY(menu_test), 'm', "exercise menu library"),
7765 CMDS(TRUE, BOTH(panel_test), 'o', "exercise panel library"),
7768 CMDS(TRUE, ONLY(pad_test), 'p', "exercise pad features"),
7770 CMDS(TRUE, ONLY(NULL), 'q', "quit"),
7772 CMDS(TRUE, ONLY(form_test), 'r', "exercise form library"),
7775 CMDS(TRUE, BOTH(overlap_test), 's', "overlapping-refresh test"),
7777 #if USE_LIBMENU && defined(TRACE)
7778 CMDS(TRUE, ONLY(trace_set), 't', "set trace level"),
7780 CMDS(TRUE, ONLY(settings_test), 'v', "show terminal name and settings"),
7781 CMDS(FALSE, ONLY(NULL), '?', "repeat this command summary")
7790 printf("This is the ncurses main menu (uppercase for wide-characters)\n");
7791 for (n = 0; n < SIZEOF(cmds); ++n) {
7792 if (top || cmds[n].recur) {
7794 #if USE_WIDEC_SUPPORT
7795 if (cmds[n].wide_func) {
7796 printf("%c,", toupper(cmds[n].code));
7799 printf("%c\t= %s\n", cmds[n].code, cmds[n].help);
7803 (void) fputs("> ", stdout);
7804 (void) fflush(stdout); /* necessary under SVr4 curses */
7807 * This used to be an 'fgets()' call (until 1996/10). However with
7808 * some runtime libraries, mixing stream I/O and 'read()' causes the
7809 * input stream to be flushed when switching between the two.
7814 if (read(fileno(stdin), &ch, (size_t) 1) <= 0) {
7815 int save_err = errno;
7817 if (save_err == EINTR) {
7820 } else if (command == 0) {
7824 } else if (command == 0 && !isspace(UChar(ch))) {
7826 } else if (ch == '\n' || ch == '\r') {
7827 if ((command == 'd') && !top) {
7828 (void) fputs("Do not nest test-d\n", stdout);
7833 (void) fputs("> ", stdout);
7834 (void) fflush(stdout);
7839 for (n = 0; n < SIZEOF(cmds); ++n) {
7840 if (cmds[n].code == command) {
7841 doit = cmds[n].narrow_func;
7844 #if USE_WIDEC_SUPPORT
7845 if (toupper(cmds[n].code) == command) {
7846 doit = cmds[n].wide_func;
7852 if (doit != NULL && doit(FALSE) == OK) {
7854 * This may be overkill; it's intended to reset everything back
7855 * to the initial terminal modes so that tests don't get in
7859 set_terminal_modes();
7864 if (command == '?') {
7865 (void) puts("This is the ncurses capability tester.");
7867 puts("You may select a test from the main menu by typing the");
7869 puts("key letter of the choice (the letter to left of the =)");
7871 puts("at the > prompt. Type `q' to exit.");
7879 /*+-------------------------------------------------------------------------
7881 --------------------------------------------------------------------------*/
7884 main(int argc, char *argv[])
7888 #ifdef NCURSES_VERSION_PATCH
7889 #if HAVE_USE_DEFAULT_COLORS
7890 int default_fg = COLOR_WHITE;
7891 int default_bg = COLOR_BLACK;
7892 bool default_colors = FALSE;
7893 #if HAVE_ASSUME_DEFAULT_COLORS
7894 bool assumed_colors = FALSE;
7898 bool monochrome = FALSE;
7899 #if HAVE_COLOR_CONTENT
7900 bool xterm_colors = FALSE;
7901 char *palette_file = 0;
7904 setlocale(LC_ALL, "");
7906 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:x")) != -1) {
7908 #ifdef NCURSES_VERSION_PATCH
7909 #if HAVE_USE_DEFAULT_COLORS
7910 #if HAVE_ASSUME_DEFAULT_COLORS
7912 assumed_colors = TRUE;
7913 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
7915 default_fg = COLOR_WHITE;
7918 default_bg = COLOR_BLACK;
7924 default_colors = TRUE;
7934 my_e_param = atoi(optarg);
7935 #ifdef NCURSES_VERSION
7936 if (my_e_param > 3) /* allow extended layouts */
7945 ripoffline(-1, rip_footer);
7948 ripoffline(1, rip_header);
7950 #endif /* HAVE_RIPOFFLINE */
7954 #if HAVE_COLOR_CONTENT
7956 palette_file = optarg;
7961 nap_msec = (int) atol(optarg);
7964 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_WIN32)
7971 save_trace = (unsigned) strtol(optarg, 0, 0);
7974 #if HAVE_COLOR_CONTENT
7976 xterm_colors = TRUE;
7985 * If there's no menus (unlikely for ncurses!), then we'll have to set
7986 * tracing on initially, just in case the user wants to test something that
7987 * doesn't involve wGetchar.
7990 /* enable debugging */
7992 curses_trace(save_trace);
7994 if (!isatty(fileno(stdin)))
7995 curses_trace(save_trace);
7996 #endif /* USE_LIBMENU */
8000 /* tell it we're going to play with soft keys */
8001 slk_init(my_e_param);
8005 /* set up null signal catcher so we can see what interrupts to getch do */
8006 signal(SIGUSR1, announce_sig);
8009 /* we must initialize the curses data structure only once */
8013 set_terminal_modes();
8016 /* tests, in general, will want these modes */
8017 UseColors = (bool) (monochrome ? FALSE : has_colors());
8021 #ifdef NCURSES_VERSION_PATCH
8022 MaxColors = COLORS; /* was > 16 ? 16 : COLORS */
8023 #if HAVE_USE_DEFAULT_COLORS
8024 if (default_colors) {
8025 use_default_colors();
8028 #if HAVE_ASSUME_DEFAULT_COLORS
8030 assume_default_colors(default_fg, default_bg);
8033 #else /* normal SVr4 curses */
8034 MaxColors = COLORS; /* was > 8 ? 8 : COLORS */
8036 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
8038 #if HAVE_COLOR_CONTENT
8039 if (can_change_color()) {
8040 init_all_colors(xterm_colors, palette_file);
8046 * Return to terminal mode, so we're guaranteed of being able to
8047 * select terminal commands even if the capabilities are wrong.
8051 #if HAVE_CURSES_VERSION
8052 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
8053 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
8054 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
8055 NCURSES_VERSION_MAJOR,
8056 NCURSES_VERSION_MINOR,
8057 NCURSES_VERSION_PATCH);
8059 (void) puts("Welcome to ncurses. Press ? for help.");
8064 ExitProgram(EXIT_SUCCESS);
8067 /* ncurses.c ends here */