1 /****************************************************************************
2 * Copyright (c) 1998-2013,2014 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.397 2014/02/01 22:29:37 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
80 extern unsigned _nc_tracing;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
110 #ifdef CURSES_WACS_ARRAY
111 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
112 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
113 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
114 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
115 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
116 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
117 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
124 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
125 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
126 #define reset_wchars(state) init_mb(state)
127 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
128 #define count_wchars(src, len, state) wcstombs(0, src, len)
129 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
130 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
135 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
136 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
137 #define reset_mbytes(state) init_mb(state)
138 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
139 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
140 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
141 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
145 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
147 #define P(string) printw("%s\n", string)
149 #define BLANK ' ' /* this is the background character */
152 static int max_colors; /* the actual number of colors we'll use */
153 static int min_colors; /* the minimum color code */
154 static bool use_colors; /* true if we use colors */
157 static int max_pairs; /* ...and the number of color pairs */
161 NCURSES_COLOR_T green;
162 NCURSES_COLOR_T blue;
165 static RGB_DATA *all_colors;
167 static void main_menu(bool);
170 failed(const char *s)
174 ExitProgram(EXIT_FAILURE);
177 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
178 * though we can rely on negative x/y values to stop the macro.
181 do_h_line(int y, int x, chtype c, int to)
184 MvHLine(y, x, c, (to) - (x));
188 do_v_line(int y, int x, chtype c, int to)
191 MvVLine(y, x, c, (to) - (y));
205 return ((c) == QUIT || (c) == ESCAPE);
207 #define case_QUIT QUIT: case ESCAPE
209 /* Common function to allow ^T to toggle trace-mode in the middle of a test
210 * so that trace-files can be made smaller.
213 wGetchar(WINDOW *win)
217 while ((c = wgetch(win)) == CTRL('T')) {
219 save_trace = _nc_tracing;
220 Trace(("TOGGLE-TRACING OFF"));
223 _nc_tracing = save_trace;
227 Trace(("TOGGLE-TRACING ON"));
234 #define Getchar() wGetchar(stdscr)
236 /* replaces wgetnstr(), since we want to be able to edit values */
238 wGetstring(WINDOW *win, char *buffer, int limit)
245 (void) wattrset(win, A_REVERSE);
247 x = (int) strlen(buffer);
249 if (x > (int) strlen(buffer))
250 x = (int) strlen(buffer);
252 wprintw(win, "%-*s", limit, buffer);
253 wmove(win, y0, x0 + x);
254 switch (ch = wGetchar(win)) {
267 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
285 if (!isprint(ch) || ch >= KEY_MIN) {
287 } else if ((int) strlen(buffer) < limit) {
289 for (j = (int) strlen(buffer) + 1; j > x; --j) {
290 buffer[j] = buffer[j - 1];
292 buffer[x++] = (char) ch;
299 wattroff(win, A_REVERSE);
304 #if USE_WIDEC_SUPPORT
308 return (ch + 0xff10 - '0');
312 make_fullwidth_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
316 *target++ = fullwidth_of(ch);
322 make_narrow_text(wchar_t *target, const char *source)
325 while ((ch = *source++) != 0) {
333 make_fullwidth_digit(cchar_t *target, int digit)
337 source[0] = fullwidth_of(digit + '0');
339 setcchar(target, source, A_NORMAL, 0, 0);
344 wGet_wchar(WINDOW *win, wint_t *result)
348 while ((c = wget_wch(win, result)) == CTRL('T')) {
350 save_trace = _nc_tracing;
351 Trace(("TOGGLE-TRACING OFF"));
354 _nc_tracing = save_trace;
358 Trace(("TOGGLE-TRACING ON"));
361 c = wget_wch(win, result);
365 #define Get_wchar(result) wGet_wchar(stdscr, result)
367 /* replaces wgetn_wstr(), since we want to be able to edit values */
369 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
378 (void) wattrset(win, A_REVERSE);
380 x = (int) wcslen(buffer);
382 if (x > (int) wcslen(buffer))
383 x = (int) wcslen(buffer);
385 /* clear the "window' */
387 wprintw(win, "%*s", limit, " ");
389 /* write the existing buffer contents */
391 waddnwstr(win, buffer, limit);
393 /* positions the cursor past character 'x' */
395 waddnwstr(win, buffer, x);
397 switch (wGet_wchar(win, &ch)) {
437 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
457 } else if ((int) wcslen(buffer) < limit) {
459 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
460 buffer[j] = buffer[j - 1];
462 buffer[x++] = (wchar_t) ch;
469 wattroff(win, A_REVERSE);
480 addstr("Press any key to continue... ");
485 Cannot(const char *what)
487 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
492 ShellOut(bool message)
495 addstr("Shelling out...");
501 IGNORE_RC(system("sh"));
504 addstr("returned from shellout.\n");
508 #ifdef NCURSES_MOUSE_VERSION
510 * This function is the same as _tracemouse(), but we cannot count on that
511 * being available in the non-debug library.
514 mouse_decode(MEVENT const *ep)
516 static char buf[80 + (5 * 10) + (32 * 15)];
518 (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {",
519 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
521 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
523 SHOW(BUTTON1_RELEASED, "release-1");
524 SHOW(BUTTON1_PRESSED, "press-1");
525 SHOW(BUTTON1_CLICKED, "click-1");
526 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
527 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
528 #if NCURSES_MOUSE_VERSION == 1
529 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
532 SHOW(BUTTON2_RELEASED, "release-2");
533 SHOW(BUTTON2_PRESSED, "press-2");
534 SHOW(BUTTON2_CLICKED, "click-2");
535 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
536 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
537 #if NCURSES_MOUSE_VERSION == 1
538 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
541 SHOW(BUTTON3_RELEASED, "release-3");
542 SHOW(BUTTON3_PRESSED, "press-3");
543 SHOW(BUTTON3_CLICKED, "click-3");
544 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
545 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
546 #if NCURSES_MOUSE_VERSION == 1
547 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
550 SHOW(BUTTON4_RELEASED, "release-4");
551 SHOW(BUTTON4_PRESSED, "press-4");
552 SHOW(BUTTON4_CLICKED, "click-4");
553 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
554 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
555 #if NCURSES_MOUSE_VERSION == 1
556 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
559 #if NCURSES_MOUSE_VERSION == 2
560 SHOW(BUTTON5_RELEASED, "release-5");
561 SHOW(BUTTON5_PRESSED, "press-5");
562 SHOW(BUTTON5_CLICKED, "click-5");
563 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
564 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
567 SHOW(BUTTON_CTRL, "ctrl");
568 SHOW(BUTTON_SHIFT, "shift");
569 SHOW(BUTTON_ALT, "alt");
570 SHOW(ALL_MOUSE_EVENTS, "all-events");
571 SHOW(REPORT_MOUSE_POSITION, "position");
575 if (buf[strlen(buf) - 1] == ' ')
576 buf[strlen(buf) - 2] = '\0';
577 (void) strcat(buf, "}");
582 show_mouse(WINDOW *win)
590 outside = !wenclose(win, event.y, event.x);
593 (void) wstandout(win);
594 waddstr(win, "KEY_MOUSE");
595 (void) wstandend(win);
597 waddstr(win, "KEY_MOUSE");
599 wprintw(win, ", %s", mouse_decode(&event));
604 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
608 wmove(win, event.y, event.x);
616 #endif /* NCURSES_MOUSE_VERSION */
618 /****************************************************************************
620 * Character input test
622 ****************************************************************************/
624 #define NUM_GETCH_FLAGS 256
625 typedef bool GetchFlags[NUM_GETCH_FLAGS];
628 setup_getch(WINDOW *win, GetchFlags flags)
630 keypad(win, flags['k']); /* should be redundant, but for testing */
631 meta(win, flags['m']); /* force this to a known state */
639 init_getch(WINDOW *win, GetchFlags flags)
641 memset(flags, FALSE, NUM_GETCH_FLAGS);
642 flags[UChar('k')] = (win == stdscr);
643 flags[UChar('m')] = TRUE;
645 setup_getch(win, flags);
649 wgetch_help(WINDOW *win, GetchFlags flags)
651 static const char *help[] =
653 "e -- toggle echo mode"
654 ,"g -- triggers a getstr test"
655 ,"k -- toggle keypad/literal mode"
656 ,"m -- toggle meta (7-bit/8-bit) mode"
659 ,"w -- create a new window"
661 ,"z -- suspend this process"
665 unsigned chk = ((SIZEOF(help) + 1) / 2);
670 printw("Type any key to see its %s value. Also:\n",
671 flags['k'] ? "keypad" : "literal");
672 for (n = 0; n < SIZEOF(help); ++n) {
673 int row = 1 + (int) (n % chk);
674 int col = (n >= chk) ? COLS / 2 : 0;
675 int flg = ((strstr(help[n], "toggle") != 0)
676 && (flags[UChar(*help[n])] != FALSE));
679 MvPrintw(row, col, "%s", help[n]);
690 wgetch_wrap(WINDOW *win, int first_y)
692 int last_y = getmaxy(win) - 1;
693 int y = getcury(win) + 1;
701 #if defined(KEY_RESIZE) && HAVE_WRESIZE
707 static WINSTACK *winstack = 0;
708 static unsigned len_winstack = 0;
721 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
723 unsigned need = (level + 1) * 2;
725 assert(level < (unsigned) COLS);
729 winstack = typeMalloc(WINSTACK, len_winstack);
730 } else if (need >= len_winstack) {
732 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
735 failed("remember_boxes");
736 winstack[level].text = txt_win;
737 winstack[level].frame = box_win;
740 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
744 /* this chunk is now done in resize_term() */
751 #define slk_repaint() /* nothing */
754 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
756 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
757 * Resize both and paint the box in the parent.
760 resize_boxes(unsigned level, WINDOW *win)
764 int high = LINES - base;
768 wnoutrefresh(stdscr);
772 for (n = 0; n < level; ++n) {
773 wresize(winstack[n].frame, high, wide);
774 wresize(winstack[n].text, high - 2, wide - 2);
777 werase(winstack[n].text);
778 box(winstack[n].frame, 0, 0);
779 wnoutrefresh(winstack[n].frame);
780 wprintw(winstack[n].text,
782 getmaxy(winstack[n].text),
783 getmaxx(winstack[n].text));
784 wnoutrefresh(winstack[n].text);
785 if (winstack[n].text == win)
790 #endif /* resize_boxes */
792 #define forget_boxes() /* nothing */
793 #define remember_boxes(level,text,frame) /* nothing */
797 * Return-code is OK/ERR or a keyname.
802 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
806 wgetch_test(unsigned level, WINDOW *win, int delay)
809 int first_y, first_x;
813 bool blocking = (delay < 0);
815 init_getch(win, flags);
816 wtimeout(win, delay);
817 getyx(win, first_y, first_x);
819 wgetch_help(win, flags);
820 wsetscrreg(win, first_y, getmaxy(win) - 1);
824 while ((c = wGetchar(win)) == ERR) {
827 (void) wprintw(win, "%05d: input error", incount);
830 (void) wprintw(win, "%05d: input timed out", incount);
832 wgetch_wrap(win, first_y);
834 if (c == ERR && blocking) {
836 wgetch_wrap(win, first_y);
837 } else if (isQuit(c)) {
839 } else if (c == 'e') {
840 flags[UChar('e')] = !flags[UChar('e')];
841 setup_getch(win, flags);
842 wgetch_help(win, flags);
843 } else if (c == 'g') {
844 waddstr(win, "getstr test: ");
846 c = wgetnstr(win, buf, sizeof(buf) - 1);
848 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
849 (int) strlen(buf), buf,
852 wgetch_wrap(win, first_y);
853 } else if (c == 'k') {
854 flags[UChar('k')] = !flags[UChar('k')];
855 setup_getch(win, flags);
856 wgetch_help(win, flags);
857 } else if (c == 'm') {
858 flags[UChar('m')] = !flags[UChar('m')];
859 setup_getch(win, flags);
860 wgetch_help(win, flags);
861 } else if (c == 's') {
863 } else if (c == 'w') {
864 int high = getmaxy(win) - 1 - first_y + 1;
865 int wide = getmaxx(win) - first_x;
867 int new_y = first_y + getbegy(win);
868 int new_x = first_x + getbegx(win);
870 getyx(win, old_y, old_x);
871 if (high > 2 && wide > 2) {
872 WINDOW *wb = newwin(high, wide, new_y, new_x);
873 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
878 remember_boxes(level, wi, wb);
879 wgetch_test(level + 1, wi, delay);
883 wgetch_help(win, flags);
884 wmove(win, old_y, old_x);
890 } else if (c == 'z') {
891 kill(getpid(), SIGTSTP);
894 wprintw(win, "Key pressed: %04o ", c);
895 #ifdef NCURSES_MOUSE_VERSION
896 if (c == KEY_MOUSE) {
899 #endif /* NCURSES_MOUSE_VERSION */
901 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
902 if (c == KEY_RESIZE) {
903 resize_boxes(level, win);
906 (void) waddstr(win, keyname(c));
907 } else if (c >= 0x80) {
908 unsigned c2 = (unsigned) c;
909 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
910 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
914 (void) wprintw(win, "%c", UChar(c));
915 else if (c2 != UChar(c))
916 (void) wprintw(win, "M-%s", unctrl(c2));
918 (void) wprintw(win, "%s", unctrl(c2));
919 waddstr(win, " (high-half character)");
922 (void) wprintw(win, "%c (ASCII printable character)", c);
924 (void) wprintw(win, "%s (ASCII control character)",
927 wgetch_wrap(win, first_y);
934 init_getch(win, flags);
938 begin_getch_test(void)
945 #ifdef NCURSES_MOUSE_VERSION
946 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
949 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
951 getnstr(buf, sizeof(buf) - 1);
955 if (isdigit(UChar(buf[0]))) {
956 delay = atoi(buf) * 100;
966 finish_getch_test(void)
968 #ifdef NCURSES_MOUSE_VERSION
969 mousemask(0, (mmask_t *) 0);
980 int delay = begin_getch_test();
983 wgetch_test(0, stdscr, delay);
989 #if USE_WIDEC_SUPPORT
991 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
992 * Resize both and paint the box in the parent.
994 #if defined(KEY_RESIZE) && HAVE_WRESIZE
996 resize_wide_boxes(unsigned level, WINDOW *win)
1000 int high = LINES - base;
1004 wnoutrefresh(stdscr);
1008 for (n = 0; n < level; ++n) {
1009 wresize(winstack[n].frame, high, wide);
1010 wresize(winstack[n].text, high - 2, wide - 2);
1013 werase(winstack[n].text);
1014 box_set(winstack[n].frame, 0, 0);
1015 wnoutrefresh(winstack[n].frame);
1016 wprintw(winstack[n].text,
1018 getmaxy(winstack[n].text),
1019 getmaxx(winstack[n].text));
1020 wnoutrefresh(winstack[n].text);
1021 if (winstack[n].text == win)
1026 #endif /* KEY_RESIZE */
1029 wcstos(const wchar_t *src)
1033 const wchar_t *tmp = src;
1034 #ifndef state_unused
1038 reset_wchars(state);
1039 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1040 unsigned have = (unsigned) need;
1041 if ((result = typeCalloc(char, have + 1)) != 0) {
1043 if (trans_wchars(result, tmp, have, &state) != have) {
1055 wget_wch_test(unsigned level, WINDOW *win, int delay)
1057 wchar_t wchar_buf[BUFSIZ];
1058 wint_t wint_buf[BUFSIZ];
1059 int first_y, first_x;
1063 bool blocking = (delay < 0);
1067 init_getch(win, flags);
1068 wtimeout(win, delay);
1069 getyx(win, first_y, first_x);
1071 wgetch_help(win, flags);
1072 wsetscrreg(win, first_y, getmaxy(win) - 1);
1073 scrollok(win, TRUE);
1076 while ((code = wGet_wchar(win, &c)) == ERR) {
1079 (void) wprintw(win, "%05d: input error", incount);
1082 (void) wprintw(win, "%05d: input timed out", incount);
1084 wgetch_wrap(win, first_y);
1086 if (code == ERR && blocking) {
1087 wprintw(win, "ERR");
1088 wgetch_wrap(win, first_y);
1089 } else if (isQuit((int) c)) {
1091 } else if (c == 'e') {
1092 flags[UChar('e')] = !flags[UChar('e')];
1093 setup_getch(win, flags);
1094 wgetch_help(win, flags);
1095 } else if (c == 'g') {
1096 waddstr(win, "getstr test: ");
1098 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1101 wprintw(win, "wgetn_wstr returns an error.");
1104 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1107 if ((temp = wcstos(wchar_buf)) != 0) {
1108 wprintw(win, "I saw %d characters:\n\t`%s'.",
1109 (int) wcslen(wchar_buf), temp);
1112 wprintw(win, "I saw %d characters (cannot convert).",
1113 (int) wcslen(wchar_buf));
1117 wgetch_wrap(win, first_y);
1118 } else if (c == 'k') {
1119 flags[UChar('k')] = !flags[UChar('k')];
1120 setup_getch(win, flags);
1121 wgetch_help(win, flags);
1122 } else if (c == 'm') {
1123 flags[UChar('m')] = !flags[UChar('m')];
1124 setup_getch(win, flags);
1125 wgetch_help(win, flags);
1126 } else if (c == 's') {
1128 } else if (c == 'w') {
1129 int high = getmaxy(win) - 1 - first_y + 1;
1130 int wide = getmaxx(win) - first_x;
1132 int new_y = first_y + getbegy(win);
1133 int new_x = first_x + getbegx(win);
1135 getyx(win, old_y, old_x);
1136 if (high > 2 && wide > 2) {
1137 WINDOW *wb = newwin(high, wide, new_y, new_x);
1138 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1143 remember_boxes(level, wi, wb);
1144 wget_wch_test(level + 1, wi, delay);
1148 wgetch_help(win, flags);
1149 wmove(win, old_y, old_x);
1154 } else if (c == 'z') {
1155 kill(getpid(), SIGTSTP);
1158 wprintw(win, "Key pressed: %04o ", (int) c);
1159 #ifdef NCURSES_MOUSE_VERSION
1160 if (c == KEY_MOUSE) {
1163 #endif /* NCURSES_MOUSE_VERSION */
1164 if (code == KEY_CODE_YES) {
1165 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1166 if (c == KEY_RESIZE) {
1167 resize_wide_boxes(level, win);
1170 (void) waddstr(win, keyname((wchar_t) c));
1172 (void) waddstr(win, key_name((wchar_t) c));
1173 if (c < 256 && iscntrl(c)) {
1174 (void) wprintw(win, " (control character)");
1176 (void) wprintw(win, " = %#x (printable character)",
1180 wgetch_wrap(win, first_y);
1187 init_getch(win, flags);
1193 int delay = begin_getch_test();
1196 wget_wch_test(0, stdscr, delay);
1198 finish_getch_test();
1203 /****************************************************************************
1205 * Character attributes test
1207 ****************************************************************************/
1209 #if HAVE_SETUPTERM || HAVE_TGETENT
1210 #define get_ncv() TIGETNUM("ncv","NC")
1211 #define get_xmc() TIGETNUM("xmc","sg")
1213 #define get_ncv() -1
1214 #define get_xmc() -1
1221 static int first = TRUE;
1222 static chtype result = 0;
1228 char *area_pointer = parsed;
1230 tgetent(buffer, getenv("TERM"));
1233 if (TIGETSTR("smso", "so"))
1234 result |= A_STANDOUT;
1235 if (TIGETSTR("smul", "us"))
1236 result |= A_UNDERLINE;
1237 if (TIGETSTR("rev", "mr"))
1238 result |= A_REVERSE;
1239 if (TIGETSTR("blink", "mb"))
1241 if (TIGETSTR("dim", "mh"))
1243 if (TIGETSTR("bold", "md"))
1245 if (TIGETSTR("smacs", "ac"))
1246 result |= A_ALTCHARSET;
1252 #define termattrs() my_termattrs()
1255 #define MAX_ATTRSTRING 31
1256 #define LEN_ATTRSTRING 26
1258 static char attr_test_string[MAX_ATTRSTRING + 1];
1261 attr_legend(WINDOW *helpwin)
1266 MvWPrintw(helpwin, row++, col,
1268 MvWPrintw(helpwin, row++, col,
1271 MvWPrintw(helpwin, row++, col,
1272 "Modify the test strings:");
1273 MvWPrintw(helpwin, row++, col,
1274 " A digit sets gaps on each side of displayed attributes");
1275 MvWPrintw(helpwin, row++, col,
1276 " </> shifts the text left/right. ");
1278 MvWPrintw(helpwin, row++, col,
1281 MvWPrintw(helpwin, row++, col,
1282 " f/F/b/F toggle foreground/background background color");
1283 MvWPrintw(helpwin, row++, col,
1284 " t/T toggle text/background color attribute");
1286 MvWPrintw(helpwin, row++, col,
1287 " a/A toggle ACS (alternate character set) mapping");
1288 MvWPrintw(helpwin, row, col,
1289 " v/V toggle video attribute to combine with each line");
1293 show_color_attr(int fg, int bg, int tx)
1296 printw(" Colors (fg %d, bg %d", fg, bg);
1298 printw(", text %d", tx);
1304 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1311 *fg = (NCURSES_COLOR_T) (*fg + 1);
1314 *fg = (NCURSES_COLOR_T) (*fg - 1);
1317 *bg = (NCURSES_COLOR_T) (*bg + 1);
1320 *bg = (NCURSES_COLOR_T) (*bg - 1);
1323 *tx = (NCURSES_COLOR_T) (*tx + 1);
1326 *tx = (NCURSES_COLOR_T) (*tx - 1);
1334 *fg = (NCURSES_COLOR_T) min_colors;
1335 if (*fg < min_colors)
1336 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1338 *bg = (NCURSES_COLOR_T) min_colors;
1339 if (*bg < min_colors)
1340 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1344 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1353 adjust_attr_string(int adjust)
1355 int first = ((int) UChar(attr_test_string[0])) + adjust;
1356 int last = first + LEN_ATTRSTRING;
1358 if (first >= ' ' && last <= '~') { /* 32..126 */
1360 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1361 attr_test_string[j] = (char) k;
1362 if (((k + 1 - first) % 5) == 0) {
1363 if (++j >= MAX_ATTRSTRING)
1365 attr_test_string[j] = ' ';
1368 while (j < MAX_ATTRSTRING)
1369 attr_test_string[j++] = ' ';
1370 attr_test_string[j] = '\0';
1377 init_attr_string(void)
1379 attr_test_string[0] = 'a';
1380 adjust_attr_string(0);
1384 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1386 int ncv = get_ncv();
1387 chtype test = attr & (chtype) (~A_ALTCHARSET);
1390 MvPrintw(row, 5, "-->");
1391 MvPrintw(row, 8, "%s mode:", name);
1392 MvPrintw(row, 24, "|");
1394 printw("%*s", skip, " ");
1396 * Just for testing, write text using the alternate character set one
1397 * character at a time (to pass its rendition directly), and use the
1398 * string operation for the other attributes.
1400 if (attr & A_ALTCHARSET) {
1404 for (s = attr_test_string; *s != '\0'; ++s) {
1409 (void) attrset(attr);
1410 addstr(attr_test_string);
1414 printw("%*s", skip, " ");
1416 if (test != A_NORMAL) {
1417 if (!(termattrs() & test)) {
1420 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1421 static const chtype table[] =
1440 for (n = 0; n < SIZEOF(table); n++) {
1441 if ((table[n] & attr) != 0
1442 && ((1 << n) & ncv) != 0) {
1450 if ((termattrs() & test) != test)
1459 NCURSES_CONST char *name;
1462 static const ATTR_TBL attrs_to_test[] = {
1463 { A_STANDOUT, "STANDOUT" },
1464 { A_REVERSE, "REVERSE" },
1466 { A_UNDERLINE, "UNDERLINE" },
1468 { A_BLINK, "BLINK" },
1469 { A_PROTECT, "PROTECT" },
1471 { A_INVIS, "INVISIBLE" },
1474 { A_ITALIC, "ITALIC" },
1476 { A_NORMAL, "NORMAL" },
1481 init_attr_list(ATTR_TBL * target, attr_t attrs)
1483 unsigned result = 0;
1486 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1487 attr_t test = attrs_to_test[n].attr;
1488 if (test == A_NORMAL || (test & attrs) != 0) {
1489 target[result++] = attrs_to_test[n];
1496 attr_getc(int *skip,
1497 NCURSES_COLOR_T *fg,
1498 NCURSES_COLOR_T *bg,
1499 NCURSES_COLOR_T *tx,
1512 if (ch < 256 && isdigit(ch)) {
1520 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1522 attr_legend(helpwin);
1545 adjust_attr_string(-1);
1548 adjust_attr_string(1);
1554 error = cycle_color_attr(ch, fg, bg, tx);
1564 /* test text attributes */
1567 int skip = get_xmc();
1568 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1569 NCURSES_COLOR_T bg = COLOR_BLACK;
1570 NCURSES_COLOR_T tx = -1;
1573 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1574 unsigned my_size = init_attr_list(my_list, termattrs());
1580 n = skip; /* make it easy */
1586 chtype normal = A_NORMAL | BLANK;
1587 chtype extras = (chtype) ac;
1590 NCURSES_PAIRS_T pair = 0;
1591 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1593 if (init_pair(pair, fg, bg) == ERR) {
1596 normal |= (chtype) COLOR_PAIR(pair);
1601 if (init_pair(pair, tx, bg) == ERR) {
1604 extras |= (chtype) COLOR_PAIR(pair);
1613 MvAddStr(0, 20, "Character attribute test display");
1615 for (j = 0; j < my_size; ++j) {
1616 bool arrow = (j == k);
1617 row = show_attr(row, n, arrow,
1625 "This terminal does %shave the magic-cookie glitch",
1626 get_xmc() > -1 ? "" : "not ");
1627 MvPrintw(row + 1, 8, "Enter '?' for help.");
1628 show_color_attr(fg, bg, tx);
1629 printw(" ACS (%d)", ac != 0);
1632 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1634 bkgdset(A_NORMAL | BLANK);
1638 Cannot("does not support video attributes.");
1642 #if USE_WIDEC_SUPPORT
1643 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1646 wide_adjust_attr_string(int adjust)
1648 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1649 int last = first + LEN_ATTRSTRING;
1651 if (first >= ' ' && last <= '~') { /* 32..126 */
1653 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1654 wide_attr_test_string[j] = k;
1655 if (((k + 1 - first) % 5) == 0) {
1656 if (++j >= MAX_ATTRSTRING)
1658 wide_attr_test_string[j] = ' ';
1661 while (j < MAX_ATTRSTRING)
1662 wide_attr_test_string[j++] = ' ';
1663 wide_attr_test_string[j] = '\0';
1670 wide_init_attr_string(void)
1672 wide_attr_test_string[0] = 'a';
1673 wide_adjust_attr_string(0);
1677 set_wide_background(NCURSES_PAIRS_T pair)
1684 setcchar(&normal, blank, A_NORMAL, pair, 0);
1690 get_wide_background(void)
1692 attr_t result = A_NORMAL;
1695 NCURSES_PAIRS_T pair;
1698 memset(&ch, 0, sizeof(ch));
1699 if (getbkgrnd(&ch) != ERR) {
1700 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1708 wide_show_attr(int row,
1712 NCURSES_PAIRS_T pair,
1715 int ncv = get_ncv();
1716 chtype test = attr & ~WA_ALTCHARSET;
1719 MvPrintw(row, 5, "-->");
1720 MvPrintw(row, 8, "%s mode:", name);
1721 MvPrintw(row, 24, "|");
1723 printw("%*s", skip, " ");
1726 * Just for testing, write text using the alternate character set one
1727 * character at a time (to pass its rendition directly), and use the
1728 * string operation for the other attributes.
1730 if (attr & WA_ALTCHARSET) {
1734 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1738 setcchar(&ch, fill, attr, pair, 0);
1742 attr_t old_attr = 0;
1743 NCURSES_PAIRS_T old_pair = 0;
1745 (void) (attr_get) (&old_attr, &old_pair, 0);
1746 (void) attr_set(attr, pair, 0);
1747 addwstr(wide_attr_test_string);
1748 (void) attr_set(old_attr, old_pair, 0);
1751 printw("%*s", skip, " ");
1753 if (test != A_NORMAL) {
1754 if (!(term_attrs() & test)) {
1757 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1758 static const attr_t table[] =
1772 for (n = 0; n < SIZEOF(table); n++) {
1773 if ((table[n] & attr) != 0
1774 && ((1 << n) & ncv) != 0) {
1782 if ((term_attrs() & test) != test)
1790 wide_attr_getc(int *skip,
1791 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1792 NCURSES_COLOR_T *tx, int *ac,
1793 unsigned *kc, unsigned limit)
1803 if (ch < 256 && isdigit(ch)) {
1811 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1812 box_set(helpwin, 0, 0);
1813 attr_legend(helpwin);
1836 wide_adjust_attr_string(-1);
1839 wide_adjust_attr_string(1);
1845 error = cycle_color_attr(ch, fg, bg, tx);
1854 wide_attr_test(void)
1855 /* test text attributes using wide-character calls */
1858 int skip = get_xmc();
1859 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1860 NCURSES_COLOR_T bg = COLOR_BLACK;
1861 NCURSES_COLOR_T tx = -1;
1864 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1865 unsigned my_size = init_attr_list(my_list, term_attrs());
1871 n = skip; /* make it easy */
1873 wide_init_attr_string();
1877 NCURSES_PAIRS_T pair = 0;
1878 NCURSES_PAIRS_T extras = 0;
1881 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1884 if (init_pair(pair, fg, bg) == ERR) {
1891 if (init_pair(extras, tx, bg) == ERR) {
1896 set_wide_background(pair);
1899 box_set(stdscr, 0, 0);
1900 MvAddStr(0, 20, "Character attribute test display");
1902 for (j = 0; j < my_size; ++j) {
1903 row = wide_show_attr(row, n, j == k,
1912 "This terminal does %shave the magic-cookie glitch",
1913 get_xmc() > -1 ? "" : "not ");
1914 MvPrintw(row + 1, 8, "Enter '?' for help.");
1915 show_color_attr(fg, bg, tx);
1916 printw(" ACS (%d)", ac != 0);
1919 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1921 set_wide_background(0);
1925 Cannot("does not support extended video attributes.");
1930 /****************************************************************************
1932 * Color support tests
1934 ****************************************************************************/
1936 static NCURSES_CONST char *the_color_names[] =
1957 show_color_name(int y, int x, int color, bool wide)
1959 if (move(y, x) != ERR) {
1964 sprintf(temp, "%02d", color);
1966 } else if (color >= 8) {
1967 sprintf(temp, "[%02d]", color);
1968 } else if (color < 0) {
1969 strcpy(temp, "default");
1971 sprintf(temp, "%.*s", 16, the_color_names[color]);
1973 printw("%-*.*s", width, width, temp);
1978 color_legend(WINDOW *helpwin, bool wide)
1983 MvWPrintw(helpwin, row++, col,
1986 MvWPrintw(helpwin, row++, col,
1987 "Use up/down arrow to scroll through the display if it is");
1988 MvWPrintw(helpwin, row++, col,
1989 "longer than one screen. Control/N and Control/P can be used");
1990 MvWPrintw(helpwin, row++, col,
1991 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1992 MvWPrintw(helpwin, row++, col,
1993 "full screen; control/B and control/F can be used here.");
1995 MvWPrintw(helpwin, row++, col,
1997 MvWPrintw(helpwin, row++, col,
1998 " a/A toggle altcharset off/on");
1999 MvWPrintw(helpwin, row++, col,
2000 " b/B toggle bold off/on");
2001 MvWPrintw(helpwin, row++, col,
2002 " n/N toggle text/number on/off");
2003 MvWPrintw(helpwin, row++, col,
2004 " r/R toggle reverse on/off");
2005 MvWPrintw(helpwin, row++, col,
2006 " w/W toggle width between 8/16 colors");
2007 #if USE_WIDEC_SUPPORT
2009 MvWPrintw(helpwin, row++, col,
2010 "Wide characters:");
2011 MvWPrintw(helpwin, row, col,
2012 " x/X toggle text between ASCII and wide-character");
2019 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2021 /* generate a color test pattern */
2028 int grid_top = top + 3;
2029 int page_size = (LINES - grid_top);
2030 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2036 bool opt_acsc = FALSE;
2037 bool opt_bold = FALSE;
2038 bool opt_revs = FALSE;
2039 bool opt_nums = FALSE;
2040 bool opt_wide = FALSE;
2043 if (COLORS * COLORS == COLOR_PAIRS) {
2044 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2045 if (pairs_max > limit)
2048 if (pairs_max > COLOR_PAIRS)
2049 pairs_max = COLOR_PAIRS;
2055 /* this assumes an 80-column line */
2059 per_row = (COLORS > 8) ? 16 : 8;
2065 per_row -= min_colors;
2067 row_limit = (pairs_max + per_row - 1) / per_row;
2070 (void) printw("There are %d color pairs and %d colors%s\n",
2072 min_colors ? " besides 'default'" : "");
2075 MvPrintw(top + 1, 0,
2076 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2079 opt_bold ? "on" : "off");
2081 /* show color names/numbers across the top */
2082 for (i = 0; i < per_row; i++)
2083 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2085 /* show a grid of colors, with color names/ numbers on the left */
2086 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2087 int row = grid_top + (i / per_row) - base_row;
2088 int col = (i % per_row + 1) * width;
2089 NCURSES_PAIRS_T pair = i;
2091 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (COLORS - min_colors)) + min_colors)
2092 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (COLORS - min_colors)) + min_colors)
2093 if (row >= 0 && move(row, col) != ERR) {
2094 NCURSES_COLOR_T fg = InxToFG(i);
2095 NCURSES_COLOR_T bg = InxToBG(i);
2097 init_pair(pair, fg, bg);
2098 attron((attr_t) COLOR_PAIR(pair));
2100 attron((attr_t) A_ALTCHARSET);
2102 attron((attr_t) A_BOLD);
2104 attron((attr_t) A_REVERSE);
2107 sprintf(numbered, "{%02X}", (int) i);
2110 printw("%-*.*s", width, width, hello);
2111 (void) attrset(A_NORMAL);
2113 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2114 show_color_name(row, 0, InxToBG(i), opt_wide);
2122 switch (wGetchar(stdscr)) {
2151 set_color_test(opt_wide, FALSE);
2154 set_color_test(opt_wide, TRUE);
2158 if (base_row <= 0) {
2166 if (base_row + page_size >= row_limit) {
2175 if (base_row <= 0) {
2178 base_row -= (page_size - 1);
2186 if (base_row + page_size >= row_limit) {
2189 base_row += page_size - 1;
2190 if (base_row + page_size >= row_limit) {
2191 base_row = row_limit - page_size - 1;
2196 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2198 color_legend(helpwin, FALSE);
2213 #if USE_WIDEC_SUPPORT
2214 /* generate a color test pattern */
2216 wide_color_test(void)
2221 int grid_top = top + 3;
2222 int page_size = (LINES - grid_top);
2223 int pairs_max = (unsigned short) (-1);
2229 bool opt_acsc = FALSE;
2230 bool opt_bold = FALSE;
2231 bool opt_revs = FALSE;
2232 bool opt_wide = FALSE;
2233 bool opt_nums = FALSE;
2234 bool opt_xchr = FALSE;
2238 if (COLORS * COLORS == COLOR_PAIRS) {
2239 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2240 if (pairs_max > limit)
2243 if (pairs_max > COLOR_PAIRS)
2244 pairs_max = COLOR_PAIRS;
2250 /* this assumes an 80-column line */
2254 per_row = (COLORS > 8) ? 16 : 8;
2260 per_row -= min_colors;
2263 make_fullwidth_text(buffer, hello);
2267 make_narrow_text(buffer, hello);
2270 row_limit = (pairs_max + per_row - 1) / per_row;
2273 (void) printw("There are %d color pairs and %d colors%s\n",
2275 min_colors ? " besides 'default'" : "");
2278 MvPrintw(top + 1, 0,
2279 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2282 opt_bold ? "on" : "off");
2284 /* show color names/numbers across the top */
2285 for (i = 0; i < per_row; i++)
2286 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2288 /* show a grid of colors, with color names/ numbers on the left */
2289 for (i = (base_row * per_row); i < pairs_max; i++) {
2290 int row = grid_top + (i / per_row) - base_row;
2291 int col = (i % per_row + 1) * width;
2292 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2294 if (row >= 0 && move(row, col) != ERR) {
2295 init_pair(pair, InxToFG(i), InxToBG(i));
2296 (void) color_set(pair, NULL);
2298 attr_on((attr_t) A_ALTCHARSET, NULL);
2300 attr_on((attr_t) A_BOLD, NULL);
2302 attr_on((attr_t) A_REVERSE, NULL);
2305 sprintf(numbered, "{%02X}", i);
2307 make_fullwidth_text(buffer, numbered);
2309 make_narrow_text(buffer, numbered);
2312 addnwstr(buffer, width);
2313 (void) attr_set(A_NORMAL, 0, NULL);
2315 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2316 show_color_name(row, 0, InxToBG(i), opt_wide);
2324 switch (wGetchar(stdscr)) {
2353 set_color_test(opt_wide, FALSE);
2356 set_color_test(opt_wide, TRUE);
2366 if (base_row <= 0) {
2374 if (base_row + page_size >= row_limit) {
2383 if (base_row <= 0) {
2386 base_row -= (page_size - 1);
2394 if (base_row + page_size >= row_limit) {
2397 base_row += page_size - 1;
2398 if (base_row + page_size >= row_limit) {
2399 base_row = row_limit - page_size - 1;
2404 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2406 color_legend(helpwin, TRUE);
2420 #endif /* USE_WIDEC_SUPPORT */
2423 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2425 NCURSES_COLOR_T red, green, blue;
2427 color_content(current, &red, &green, &blue);
2431 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2434 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2437 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2441 if (init_color(current, red, green, blue) == ERR)
2446 init_all_colors(void)
2450 for (c = 0; c < COLORS; ++c)
2453 all_colors[c].green,
2454 all_colors[c].blue);
2457 #define scaled_rgb(n) ((255 * (n)) / 1000)
2461 /* display the color test pattern, without trying to edit colors */
2465 int this_c = 0, value = 0, field = 0;
2468 int page_size = (LINES - 6);
2473 for (i = 0; i < max_colors; i++)
2474 init_pair((NCURSES_PAIRS_T) i,
2475 (NCURSES_COLOR_T) COLOR_WHITE,
2476 (NCURSES_COLOR_T) i);
2478 MvPrintw(LINES - 2, 0, "Number: %d", value);
2481 NCURSES_COLOR_T red, green, blue;
2484 MvAddStr(0, 20, "Color RGB Value Editing");
2487 for (i = (NCURSES_COLOR_T) top_color;
2488 (i - top_color < page_size)
2489 && (i < max_colors); i++) {
2492 sprintf(numeric, "[%d]", i);
2493 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2494 (i == current ? '>' : ' '),
2495 (i < (int) SIZEOF(the_color_names)
2496 ? the_color_names[i] : numeric));
2497 (void) attrset((attr_t) COLOR_PAIR(i));
2499 (void) attrset(A_NORMAL);
2501 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2503 if (current == i && field == 0)
2505 printw("%04d", (int) red);
2506 if (current == i && field == 0)
2507 (void) attrset(A_NORMAL);
2509 if (current == i && field == 1)
2511 printw("%04d", (int) green);
2512 if (current == i && field == 1)
2513 (void) attrset(A_NORMAL);
2515 if (current == i && field == 2)
2517 printw("%04d", (int) blue);
2518 if (current == i && field == 2)
2519 (void) attrset(A_NORMAL);
2520 (void) attrset(A_NORMAL);
2521 printw(" ( %3d %3d %3d )",
2522 (int) scaled_rgb(red),
2523 (int) scaled_rgb(green),
2524 (int) scaled_rgb(blue));
2527 MvAddStr(LINES - 3, 0,
2528 "Use up/down to select a color, left/right to change fields.");
2529 MvAddStr(LINES - 2, 0,
2530 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2532 move(2 + current - top_color, 0);
2536 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2543 current -= (page_size - 1);
2550 if (current < (max_colors - 1))
2551 current += (page_size - 1);
2558 current = (current == 0 ? (max_colors - 1) : current - 1);
2563 current = (current == (max_colors - 1) ? 0 : current + 1);
2567 field = (field == 2 ? 0 : field + 1);
2571 field = (field == 0 ? 2 : field - 1);
2584 value = value * 10 + (this_c - '0');
2588 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2592 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2596 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2601 P(" RGB Value Editing Help");
2603 P("You are in the RGB value editor. Use the arrow keys to select one of");
2604 P("the fields in one of the RGB triples of the current colors; the one");
2605 P("currently selected will be reverse-video highlighted.");
2607 P("To change a field, enter the digits of the new value; they are echoed");
2608 P("as entered. Finish by typing `='. The change will take effect instantly.");
2609 P("To increment or decrement a value, use the same procedure, but finish");
2610 P("with a `+' or `-'.");
2612 P("Press 'm' to invoke the top-level menu with the current color settings.");
2613 P("To quit, do ESC");
2622 for (i = 0; i < max_colors; i++)
2623 init_pair((NCURSES_PAIRS_T) i,
2624 (NCURSES_COLOR_T) COLOR_WHITE,
2625 (NCURSES_COLOR_T) i);
2639 if (current >= max_colors)
2640 current = max_colors - 1;
2641 if (current < top_color)
2642 top_color = current;
2643 if (current - top_color >= page_size)
2644 top_color = current - (page_size - 1);
2646 MvPrintw(LINES - 1, 0, "Number: %d", value);
2654 * ncurses does not reset each color individually when calling endwin().
2661 /****************************************************************************
2663 * Alternate character-set stuff
2665 ****************************************************************************/
2667 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
2673 if ((*at_code += 1) >= limit)
2678 *at_code = limit - 1;
2687 *attr = list[*at_code].attr;
2692 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
2694 bool result = FALSE;
2704 if ((*fg += 1) >= COLORS)
2712 if ((*bg += 1) >= COLORS)
2720 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2723 if (init_pair(*pair,
2724 (NCURSES_COLOR_T) *fg,
2725 (NCURSES_COLOR_T) *bg) == ERR) {
2734 /****************************************************************************
2736 * Soft-key label test
2738 ****************************************************************************/
2743 #define SLK_WORK (SLK_HELP + 3)
2748 static const char *table[] =
2750 "Available commands are:"
2752 ,"^L -- repaint this message and activate soft keys"
2753 ,"a/d -- activate/disable soft keys"
2754 ,"c -- set centered format for labels"
2755 ,"l -- set left-justified format for labels"
2756 ,"r -- set right-justified format for labels"
2757 ,"[12345678] -- set label; labels are numbered 1 through 8"
2758 ,"e -- erase stdscr (should not erase labels)"
2759 ,"s -- test scrolling of shortened screen"
2760 ,"v/V -- cycle through video attributes"
2762 ,"F/f/B/b -- cycle through foreground/background colors"
2764 ,"ESC -- return to main menu"
2766 ,"Note: if activating the soft keys causes your terminal to scroll up"
2767 ,"one line, your terminal auto-scrolls when anything is written to the"
2768 ,"last screen position. The ncurses code does not yet handle this"
2774 for (j = 0; j < SIZEOF(table); ++j) {
2782 call_slk_color(int fg, int bg)
2784 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
2786 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2796 /* exercise the soft keys */
2801 chtype attr = A_NORMAL;
2802 unsigned at_code = 0;
2804 int fg = COLOR_BLACK;
2805 int bg = COLOR_WHITE;
2806 NCURSES_PAIRS_T pair = 0;
2808 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
2809 unsigned my_size = init_attr_list(my_list, termattrs());
2814 call_slk_color(fg, bg);
2824 MvAddStr(0, 20, "Soft Key Exerciser");
2839 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2840 while ((c = Getchar()) != 'Q' && (c != ERR))
2868 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2870 if ((s = slk_label(c - '0')) != 0) {
2871 strncpy(buf, s, (size_t) 8);
2873 wGetstring(stdscr, buf, 8);
2874 slk_set((c - '0'), buf, fmt);
2883 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2885 wnoutrefresh(stdscr);
2890 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
2897 if (cycle_colors(c, &fg, &bg, &pair)) {
2899 call_slk_color(fg, bg);
2909 } while (!isQuit(c = Getchar()));
2917 #if USE_WIDEC_SUPPORT
2921 /* exercise the soft keys */
2924 wchar_t buf[SLKLEN + 1];
2926 chtype attr = A_NORMAL;
2927 unsigned at_code = 0;
2928 int fg = COLOR_BLACK;
2929 int bg = COLOR_WHITE;
2930 NCURSES_PAIRS_T pair = 0;
2931 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
2932 unsigned my_size = init_attr_list(my_list, term_attrs());
2936 call_slk_color(fg, bg);
2943 attr_on(WA_BOLD, NULL);
2944 MvAddStr(0, 20, "Soft Key Exerciser");
2945 attr_off(WA_BOLD, NULL);
2959 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2960 while ((c = Getchar()) != 'Q' && (c != ERR))
2988 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2990 if ((s = slk_label(c - '0')) != 0) {
2991 char *temp = strdup(s);
2992 size_t used = strlen(temp);
2993 size_t want = SLKLEN;
2995 #ifndef state_unused
3000 while (want > 0 && used != 0) {
3001 const char *base = s;
3002 reset_mbytes(state);
3003 test = count_mbytes(base, 0, &state);
3004 if (test == (size_t) -1) {
3006 } else if (test > want) {
3009 reset_mbytes(state);
3010 trans_mbytes(buf, base, want, &state);
3016 wGet_wstring(stdscr, buf, SLKLEN);
3017 slk_wset((c - '0'), buf, fmt);
3028 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3029 call_slk_color(fg, bg);
3034 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3035 call_slk_color(fg, bg);
3038 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3040 wnoutrefresh(stdscr);
3044 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3045 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3051 if (cycle_colors(c, &fg, &bg, &pair)) {
3053 call_slk_color(fg, bg);
3063 } while (!isQuit(c = Getchar()));
3071 #endif /* SLK_INIT */
3074 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3077 unsigned last = 255;
3083 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3088 for (code = first; code <= last; ++code) {
3089 int row = (int) (2 + (code / 16));
3090 int col = (int) (5 * (code % 16));
3091 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3092 for (count = 1; count < repeat; ++count) {
3093 addch(colored_chtype(code, attr, pair));
3100 * Show a slice of 32 characters, allowing those to be repeated up to the
3103 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3104 * terminal to perform functions. The remaining codes can be graphic.
3107 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3110 unsigned first = (unsigned) base;
3111 unsigned last = first + (unsigned) pagesize - 2;
3112 bool C1 = (first == 128);
3117 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3118 C1 ? "C1" : "GR", first, last);
3122 for (code = first; code <= last; code++) {
3124 int row = 2 + ((int) (code - first) % (pagesize / 2));
3125 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3127 sprintf(tmp, "%3u (0x%x)", code, code);
3128 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3132 nodelay(stdscr, TRUE);
3133 echochar(colored_chtype(code, attr, pair));
3135 /* (yes, this _is_ crude) */
3136 while ((reply = Getchar()) != ERR) {
3137 addch(UChar(reply));
3140 nodelay(stdscr, FALSE);
3142 } while (--count > 0);
3149 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3155 MvPrintw(0, 20, "Display of PC Character Codes");
3159 for (code = 0; code < 16; ++code) {
3160 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3162 for (code = 0; code < 256; code++) {
3164 int row = 3 + (int) (code / 16) + (code >= 128);
3165 int col = 8 + (int) (code % 16) * PC_COLS;
3166 if ((code % 16) == 0)
3167 MvPrintw(row, 0, "0x%02x:", code);
3178 * Skip the ones that do not work.
3182 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3185 } while (--count > 0);
3190 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3194 attr |= (attr_t) COLOR_PAIR(pair);
3198 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3203 colored_chtype(ACS_VLINE, attr, pair),
3204 colored_chtype(ACS_VLINE, attr, pair),
3205 colored_chtype(ACS_HLINE, attr, pair),
3206 colored_chtype(ACS_HLINE, attr, pair),
3207 colored_chtype(ACS_ULCORNER, attr, pair),
3208 colored_chtype(ACS_URCORNER, attr, pair),
3209 colored_chtype(ACS_LLCORNER, attr, pair),
3210 colored_chtype(ACS_LRCORNER, attr, pair));
3211 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3212 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3213 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3214 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3215 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3216 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3217 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3223 show_1_acs(int n, int repeat, const char *name, chtype code)
3225 const int height = 16;
3226 int row = 2 + (n % height);
3227 int col = (n / height) * COLS / 2;
3229 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3232 } while (--repeat > 0);
3237 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3238 /* display the ACS character set */
3242 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3246 MvAddStr(0, 20, "Display of the ACS Character Set");
3250 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3251 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3252 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3253 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3255 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3256 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3257 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3258 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3260 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3261 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3264 * HPUX's ACS definitions are broken here. Just give up.
3266 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3267 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3268 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3269 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3270 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3272 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3273 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3274 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3275 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3276 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3277 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3278 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3279 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3280 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3282 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3283 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3284 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3286 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3287 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3288 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3289 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3290 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3291 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3300 char *term = getenv("TERM");
3301 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3304 chtype attr = A_NORMAL;
3307 int fg = COLOR_BLACK;
3308 int bg = COLOR_BLACK;
3309 unsigned at_code = 0;
3310 NCURSES_PAIRS_T pair = 0;
3311 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3312 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3313 unsigned my_size = init_attr_list(my_list, termattrs());
3321 ToggleAcs(last_show_acs, show_acs_chars);
3325 ToggleAcs(last_show_acs, show_pc_chars);
3330 if (pagesize == 32) {
3337 ToggleAcs(last_show_acs, show_box_chars);
3363 if (repeat < (COLS / 4))
3371 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3372 || cycle_colors(c, &fg, &bg, &pair)) {
3379 if (pagesize != 32) {
3380 show_256_chars(repeat, attr, pair);
3381 } else if (last_show_acs != 0) {
3382 last_show_acs(repeat, attr, pair);
3384 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3387 MvPrintw(LINES - 3, 0,
3388 "Note: ANSI terminals may not display C1 characters.");
3389 MvPrintw(LINES - 2, 0,
3390 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3393 MvPrintw(LINES - 1, 0,
3394 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3395 my_list[at_code].name,
3398 MvPrintw(LINES - 1, 0,
3399 "v/V cycles through video attributes (%s).",
3400 my_list[at_code].name);
3403 } while (!isQuit(c = Getchar()));
3410 #if USE_WIDEC_SUPPORT
3412 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3418 TEST_CCHAR(src, count, {
3419 attr |= (test_attrs & A_ALTCHARSET);
3420 setcchar(dst, test_wch, attr, pair, NULL);
3430 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3431 * display. If there are no repeats, we could normally display 16 lines of 64
3432 * characters (1024 total). However, taking repeats and double-width cells
3433 * into account, use 256 characters for the page.
3436 show_paged_widechars(int base,
3441 NCURSES_PAIRS_T pair)
3443 int first = base * pagesize;
3444 int last = first + pagesize - 1;
3452 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3455 for (code = first; (int) code <= last; code++) {
3456 int row = (2 + ((int) code - first) / per_line);
3457 int col = 5 * ((int) code % per_line);
3460 memset(&codes, 0, sizeof(codes));
3462 setcchar(&temp, codes, attr, pair, 0);
3464 if (wcwidth(code) == 0 && code != 0) {
3465 addch((chtype) space |
3466 (A_REVERSE ^ attr) |
3467 (attr_t) COLOR_PAIR(pair));
3470 for (count = 1; count < repeat; ++count) {
3477 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3481 int last = first + 31;
3485 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3488 for (code = first; (int) code <= last; code++) {
3489 int row = 2 + ((code - first) % 16);
3490 int col = ((code - first) / 16) * COLS / 2;
3496 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3497 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3499 memset(&codes, 0, sizeof(codes));
3501 setcchar(&temp, codes, attr, pair, 0);
3505 * Give non-spacing characters something to combine with. If we
3506 * don't, they'll bunch up in a heap on the space after the ":".
3507 * Mark them with reverse-video to make them simpler to find on
3510 if (wcwidth(code) == 0) {
3511 addch((chtype) space |
3512 (A_REVERSE ^ attr) |
3513 (attr_t) COLOR_PAIR(pair));
3516 * This uses echo_wchar(), for comparison with the normal 'f'
3517 * test (and to make a test-case for echo_wchar()). The screen
3518 * may flicker because the erase() at the top of the function
3519 * is met by the builtin refresh() in echo_wchar().
3523 * The repeat-count may make text wrap - avoid that.
3525 getyx(stdscr, y, x);
3527 if (x >= col + (COLS / 2) - 2)
3529 } while (--count > 0);
3534 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3536 const int height = 16;
3537 int row = 2 + (n % height);
3538 int col = (n / height) * COLS / 2;
3540 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3541 while (--repeat >= 0) {
3547 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3550 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3551 /* display the wide-ACS character set */
3557 /*#define BOTH2(name) #name, &(name) */
3558 #define BOTH2(name) #name, MERGE_ATTR(name)
3562 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3566 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3567 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3568 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3569 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3571 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3572 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3573 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3574 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3576 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3577 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3579 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3580 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3581 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3582 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3584 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3585 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3586 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3587 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3588 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3589 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3590 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3591 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3592 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3594 #ifdef CURSES_WACS_ARRAY
3595 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3596 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3597 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3599 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3600 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3601 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3602 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3603 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3604 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3610 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3611 /* display the wide-ACS character set */
3617 /*#define BOTH2(name) #name, &(name) */
3618 #define BOTH2(name) #name, MERGE_ATTR(name)
3622 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3626 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3627 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3628 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3629 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3631 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3632 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3633 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3634 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3636 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3637 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3639 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3640 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3641 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3642 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3644 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3645 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3646 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3647 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3648 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3649 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3650 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3651 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3652 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3654 #ifdef CURSES_WACS_ARRAY
3655 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3656 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3657 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3659 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3660 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3661 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3662 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3663 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3664 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3671 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3672 /* display the wide-ACS character set */
3678 /*#define BOTH2(name) #name, &(name) */
3679 #define BOTH2(name) #name, MERGE_ATTR(name)
3683 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3687 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
3688 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
3689 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
3690 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
3692 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
3693 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
3694 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
3695 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
3697 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
3698 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
3700 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3701 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3702 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3703 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3705 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3706 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3707 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3708 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3709 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3710 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3711 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3712 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3713 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3715 #ifdef CURSES_WACS_ARRAY
3716 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3717 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3718 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3720 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3721 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3722 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3723 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3724 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3725 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3732 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3735 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3742 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3747 MERGE_ATTR(0, WACS_VLINE),
3748 MERGE_ATTR(1, WACS_VLINE),
3749 MERGE_ATTR(2, WACS_HLINE),
3750 MERGE_ATTR(3, WACS_HLINE),
3751 MERGE_ATTR(4, WACS_ULCORNER),
3752 MERGE_ATTR(5, WACS_URCORNER),
3753 MERGE_ATTR(6, WACS_LLCORNER),
3754 MERGE_ATTR(7, WACS_LRCORNER));
3756 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3757 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3758 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3759 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3760 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3761 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3762 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3770 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
3772 const int height = 16;
3773 int row = 2 + (n % height);
3774 int col = (n / height) * COLS / 2;
3777 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3778 (void) attr_set(attr, pair, 0);
3779 addstr(strncpy(temp, code, 20));
3780 (void) attr_set(A_NORMAL, 0, 0);
3784 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3787 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3794 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3798 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3799 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3800 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3801 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3803 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3804 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3805 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3806 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3808 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3809 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3811 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3812 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3813 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3814 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3816 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3817 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3818 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3819 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3820 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3821 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3822 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3823 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3824 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3825 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3826 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3827 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3829 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3830 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3831 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3832 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3833 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3834 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3839 /* display the wide-ACS character set */
3841 wide_acs_display(void)
3848 chtype attr = A_NORMAL;
3849 int fg = COLOR_BLACK;
3850 int bg = COLOR_BLACK;
3851 unsigned at_code = 0;
3852 NCURSES_PAIRS_T pair = 0;
3853 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3854 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3855 unsigned my_size = init_attr_list(my_list, term_attrs());
3863 ToggleAcs(last_show_wacs, show_wacs_chars);
3867 ToggleAcs(last_show_wacs, show_wacs_chars_double);
3872 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
3876 if (pagesize == 32) {
3883 ToggleAcs(last_show_wacs, show_wbox_chars);
3886 ToggleAcs(last_show_wacs, show_utf8_chars);
3889 if (c < 256 && isdigit(c)) {
3892 } else if (c == '+') {
3895 } else if (c == '-' && digit > 0) {
3898 } else if (c == '>' && repeat < (COLS / 4)) {
3900 } else if (c == '<' && repeat > 1) {
3902 } else if (c == '_') {
3903 space = (space == ' ') ? '_' : ' ';
3905 } else if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3906 || cycle_colors(c, &fg, &bg, &pair)) {
3907 if (last_show_wacs != 0)
3915 if (pagesize != 32) {
3916 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
3917 } else if (last_show_wacs != 0) {
3918 last_show_wacs(repeat, attr, pair);
3920 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3923 MvPrintw(LINES - 4, 0,
3924 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
3925 MvPrintw(LINES - 3, 2,
3926 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
3928 MvPrintw(LINES - 2, 2,
3929 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3930 my_list[at_code].name,
3933 MvPrintw(LINES - 2, 2,
3934 "v/V cycles through video attributes (%s).",
3935 my_list[at_code].name);
3938 } while (!isQuit(c = Getchar()));
3948 * Graphic-rendition test (adapted from vttest)
3951 test_sgr_attributes(void)
3955 for (pass = 0; pass < 2; pass++) {
3956 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3958 /* Use non-default colors if possible to exercise bce a little */
3960 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3961 normal |= (chtype) COLOR_PAIR(1);
3965 MvPrintw(1, 20, "Graphic rendition test pattern:");
3967 MvPrintw(4, 1, "vanilla");
3969 #define set_sgr(mask) bkgdset((normal^(mask)));
3971 MvPrintw(4, 40, "bold");
3973 set_sgr(A_UNDERLINE);
3974 MvPrintw(6, 6, "underline");
3976 set_sgr(A_BOLD | A_UNDERLINE);
3977 MvPrintw(6, 45, "bold underline");
3980 MvPrintw(8, 1, "blink");
3982 set_sgr(A_BLINK | A_BOLD);
3983 MvPrintw(8, 40, "bold blink");
3985 set_sgr(A_UNDERLINE | A_BLINK);
3986 MvPrintw(10, 6, "underline blink");
3988 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3989 MvPrintw(10, 45, "bold underline blink");
3992 MvPrintw(12, 1, "negative");
3994 set_sgr(A_BOLD | A_REVERSE);
3995 MvPrintw(12, 40, "bold negative");
3997 set_sgr(A_UNDERLINE | A_REVERSE);
3998 MvPrintw(14, 6, "underline negative");
4000 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4001 MvPrintw(14, 45, "bold underline negative");
4003 set_sgr(A_BLINK | A_REVERSE);
4004 MvPrintw(16, 1, "blink negative");
4006 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4007 MvPrintw(16, 40, "bold blink negative");
4009 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4010 MvPrintw(18, 6, "underline blink negative");
4012 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4013 MvPrintw(18, 45, "bold underline blink negative");
4016 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4022 bkgdset(A_NORMAL | BLANK);
4027 /****************************************************************************
4029 * Windows and scrolling tester.
4031 ****************************************************************************/
4033 #define BOTLINES 4 /* number of line stolen from screen bottom */
4039 #define FRAME struct frame
4048 #if defined(NCURSES_VERSION)
4049 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
4050 #define is_keypad(win) (win)->_use_keypad
4051 #define is_scrollok(win) (win)->_scroll
4052 #elif !defined(is_keypad)
4053 #define is_keypad(win) FALSE
4054 #define is_scrollok(win) FALSE
4057 #define is_keypad(win) FALSE
4058 #define is_scrollok(win) FALSE
4062 frame_win(FRAME * curp)
4064 return (curp != 0) ? curp->wind : stdscr;
4067 /* We need to know if these flags are actually set, so don't look in FRAME.
4068 * These names are known to work with SVr4 curses as well as ncurses. The
4069 * _use_keypad name does not work with Solaris 8.
4072 HaveKeypad(FRAME * curp)
4074 WINDOW *win = frame_win(curp);
4076 return is_keypad(win);
4080 HaveScroll(FRAME * curp)
4082 WINDOW *win = frame_win(curp);
4084 return is_scrollok(win);
4088 newwin_legend(FRAME * curp)
4090 static const struct {
4095 "^C = create window", 0
4098 "^N = next window", 0
4101 "^P = previous window", 0
4104 "^F = scroll forward", 0
4107 "^B = scroll backward", 0
4110 "^K = keypad(%s)", 1
4113 "^S = scrollok(%s)", 2
4116 "^W = save window to file", 0
4119 "^R = restore window", 0
4132 bool do_keypad = HaveKeypad(curp);
4133 bool do_scroll = HaveScroll(curp);
4137 for (n = 0; n < SIZEOF(legend); n++) {
4138 switch (legend[n].code) {
4140 strcpy(buf, legend[n].msg);
4143 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
4146 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
4149 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
4152 x = getcurx(stdscr);
4153 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4160 transient(FRAME * curp, NCURSES_CONST char *msg)
4162 newwin_legend(curp);
4164 MvAddStr(LINES - 1, 0, msg);
4170 printw("%s characters are echoed, window should %sscroll.",
4171 HaveKeypad(curp) ? "Non-arrow" : "All other",
4172 HaveScroll(curp) ? "" : "not ");
4177 newwin_report(FRAME * curp)
4178 /* report on the cursor's current position, then restore it */
4180 WINDOW *win = frame_win(curp);
4184 transient(curp, (char *) 0);
4186 move(LINES - 1, COLS - 17);
4187 printw("Y = %2d X = %2d", y, x);
4195 selectcell(int uli, int ulj, int lri, int lrj)
4196 /* arrows keys move cursor, return location at current on non-arrow key */
4198 static pair res; /* result cell */
4199 int si = lri - uli + 1; /* depth of the select area */
4200 int sj = lrj - ulj + 1; /* width of the select area */
4201 int i = 0, j = 0; /* offsets into the select area */
4206 move(uli + i, ulj + j);
4207 newwin_report((FRAME *) 0);
4209 switch (Getchar()) {
4223 return ((pair *) 0);
4224 #ifdef NCURSES_MOUSE_VERSION
4230 if (event.y > uli && event.x > ulj) {
4251 outerbox(pair ul, pair lr, bool onoff)
4252 /* draw or erase a box *outside* the given pair of corners */
4254 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4255 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4256 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4257 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4258 move(ul.y - 1, ul.x);
4259 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4260 move(ul.y, ul.x - 1);
4261 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4262 move(lr.y + 1, ul.x);
4263 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4264 move(ul.y, lr.x + 1);
4265 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4270 /* Ask user for a window definition */
4277 addstr("Use arrows to move cursor, anything else to mark corner 1");
4279 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4280 return ((WINDOW *) 0);
4281 memcpy(&ul, tmp, sizeof(pair));
4282 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4285 addstr("Use arrows to move cursor, anything else to mark corner 2");
4287 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4289 return ((WINDOW *) 0);
4290 memcpy(&lr, tmp, sizeof(pair));
4292 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4294 outerbox(ul, lr, TRUE);
4306 newwin_move(FRAME * curp, int dy, int dx)
4308 WINDOW *win = frame_win(curp);
4312 getyx(win, cur_y, cur_x);
4313 getmaxyx(win, max_y, max_x);
4314 if ((cur_x += dx) < 0)
4316 else if (cur_x >= max_x)
4318 if ((cur_y += dy) < 0)
4320 else if (cur_y >= max_y)
4322 wmove(win, cur_y, cur_x);
4326 delete_framed(FRAME * fp, bool showit)
4331 fp->last->next = fp->next;
4332 fp->next->last = fp->last;
4340 np = (fp == fp->next) ? 0 : fp->next;
4347 acs_and_scroll(void)
4348 /* Demonstrate windows */
4351 FRAME *current = (FRAME *) 0, *neww;
4353 #if HAVE_PUTWIN && HAVE_GETWIN
4357 #define DUMPFILE "screendump"
4359 #ifdef NCURSES_MOUSE_VERSION
4360 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4365 transient((FRAME *) 0, (char *) 0);
4368 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4369 failed("acs_and_scroll");
4372 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4373 failed("acs_and_scroll");
4378 if (current == 0) { /* First element, */
4379 neww->next = neww; /* so point it at itself */
4382 neww->next = current->next;
4383 neww->last = current;
4384 neww->last->next = neww;
4385 neww->next->last = neww;
4388 /* SVr4 curses sets the keypad on all newly-created windows to
4389 * false. Someone reported that PDCurses makes new windows inherit
4390 * this flag. Remove the following 'keypad()' call to test this
4392 keypad(current->wind, TRUE);
4393 current->do_keypad = HaveKeypad(current);
4394 current->do_scroll = HaveScroll(current);
4397 case CTRL('N'): /* go to next window */
4399 current = current->next;
4402 case CTRL('P'): /* go to previous window */
4404 current = current->last;
4407 case CTRL('F'): /* scroll current window forward */
4409 wscrl(frame_win(current), 1);
4412 case CTRL('B'): /* scroll current window backwards */
4414 wscrl(frame_win(current), -1);
4417 case CTRL('K'): /* toggle keypad mode for current */
4419 current->do_keypad = !current->do_keypad;
4420 keypad(current->wind, current->do_keypad);
4426 current->do_scroll = !current->do_scroll;
4427 scrollok(current->wind, current->do_scroll);
4431 #if HAVE_PUTWIN && HAVE_GETWIN
4432 case CTRL('W'): /* save and delete window */
4433 if ((current != 0) && (current == current->next)) {
4434 transient(current, "Will not save/delete ONLY window");
4436 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4437 transient(current, "Can't open screen dump file");
4439 (void) putwin(frame_win(current), fp);
4442 current = delete_framed(current, TRUE);
4446 case CTRL('R'): /* restore window */
4447 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4448 transient(current, "Can't open screen dump file");
4450 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4452 neww->next = current ? current->next : 0;
4453 neww->last = current;
4454 if (neww->last != 0)
4455 neww->last->next = neww;
4456 if (neww->next != 0)
4457 neww->next->last = neww;
4459 neww->wind = getwin(fp);
4461 wrefresh(neww->wind);
4463 failed("acs_and_scroll");
4471 case CTRL('X'): /* resize window */
4478 addstr("Use arrows to move cursor, anything else to mark new corner");
4481 getbegyx(current->wind, ul.y, ul.x);
4483 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);