X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fncurses.c;h=9a90d4018dc9fbdb740e2d9988d48cd15508fce3;hp=28d3de758aa0ad9b6685b731223aa895eed1b52f;hb=445bfe6a0fb691e3433d586a188be2ebe062384b;hpb=987faea6703ceb2c59ac9787f99eda67e3fe7676 diff --git a/test/ncurses.c b/test/ncurses.c index 28d3de75..9a90d401 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc. * + * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -40,7 +40,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.401 2014/06/21 18:37:29 tom Exp $ +$Id: ncurses.c,v 1.429 2016/01/03 01:50:10 tom Exp $ ***************************************************************************/ @@ -303,9 +303,9 @@ wGetstring(WINDOW *win, char *buffer, int limit) #if USE_WIDEC_SUPPORT static wchar_t -fullwidth_of(int ch) +fullwidth_digit(int ch) { - return (ch + 0xff10 - '0'); + return (wchar_t) (ch + 0xff10 - '0'); } static void @@ -313,7 +313,7 @@ make_fullwidth_text(wchar_t *target, const char *source) { int ch; while ((ch = *source++) != 0) { - *target++ = fullwidth_of(ch); + *target++ = fullwidth_digit(ch); } *target = 0; } @@ -323,7 +323,7 @@ make_narrow_text(wchar_t *target, const char *source) { int ch; while ((ch = *source++) != 0) { - *target++ = ch; + *target++ = (wchar_t) ch; } *target = 0; } @@ -334,7 +334,7 @@ make_fullwidth_digit(cchar_t *target, int digit) { wchar_t source[2]; - source[0] = fullwidth_of(digit + '0'); + source[0] = fullwidth_digit(digit + '0'); source[1] = 0; setcchar(target, source, A_NORMAL, 0, 0); } @@ -636,15 +636,22 @@ setup_getch(WINDOW *win, GetchFlags flags) } static void -init_getch(WINDOW *win, GetchFlags flags) +init_getch(WINDOW *win, GetchFlags flags, int delay) { memset(flags, FALSE, NUM_GETCH_FLAGS); flags[UChar('k')] = (win == stdscr); flags[UChar('m')] = TRUE; + flags[UChar('t')] = (delay != 0); setup_getch(win, flags); } +static bool +blocking_getch(GetchFlags flags, int delay) +{ + return ((delay < 0) && flags['t']); +} + static void wgetch_help(WINDOW *win, GetchFlags flags) { @@ -655,7 +662,8 @@ wgetch_help(WINDOW *win, GetchFlags flags) ,"k -- toggle keypad/literal mode" ,"m -- toggle meta (7-bit/8-bit) mode" ,"^q -- quit" - ,"s -- shell out\n" + ,"s -- shell out" + ,"t -- toggle timeout" ,"w -- create a new window" #ifdef SIGTSTP ,"z -- suspend this process" @@ -810,9 +818,9 @@ wgetch_test(unsigned level, WINDOW *win, int delay) int c; int incount = 0; GetchFlags flags; - bool blocking = (delay < 0); - init_getch(win, flags); + init_getch(win, flags, delay); + notimeout(win, FALSE); wtimeout(win, delay); getyx(win, first_y, first_x); @@ -823,7 +831,7 @@ wgetch_test(unsigned level, WINDOW *win, int delay) for (;;) { while ((c = wGetchar(win)) == ERR) { incount++; - if (blocking) { + if (blocking_getch(flags, delay)) { (void) wprintw(win, "%05d: input error", incount); break; } else { @@ -831,7 +839,7 @@ wgetch_test(unsigned level, WINDOW *win, int delay) } wgetch_wrap(win, first_y); } - if (c == ERR && blocking) { + if (c == ERR && blocking_getch(flags, delay)) { wprintw(win, "ERR"); wgetch_wrap(win, first_y); } else if (isQuit(c)) { @@ -860,6 +868,10 @@ wgetch_test(unsigned level, WINDOW *win, int delay) wgetch_help(win, flags); } else if (c == 's') { ShellOut(TRUE); + } else if (c == 't') { + notimeout(win, flags[UChar('t')]); + flags[UChar('t')] = !flags[UChar('t')]; + wgetch_help(win, flags); } else if (c == 'w') { int high = getmaxy(win) - 1 - first_y + 1; int wide = getmaxx(win) - first_x; @@ -931,7 +943,7 @@ wgetch_test(unsigned level, WINDOW *win, int delay) wtimeout(win, -1); if (!level) - init_getch(win, flags); + init_getch(win, flags, delay); } static int @@ -943,7 +955,7 @@ begin_getch_test(void) refresh(); #ifdef NCURSES_MOUSE_VERSION - mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); + mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0); #endif (void) printw("Delay in 10ths of a second ( for blocking input)? "); @@ -958,7 +970,7 @@ begin_getch_test(void) delay = -1; } raw(); - move(5, 0); + move(6, 0); return delay; } @@ -1060,11 +1072,11 @@ wget_wch_test(unsigned level, WINDOW *win, int delay) wint_t c; int incount = 0; GetchFlags flags; - bool blocking = (delay < 0); int code; char *temp; - init_getch(win, flags); + init_getch(win, flags, delay); + notimeout(win, FALSE); wtimeout(win, delay); getyx(win, first_y, first_x); @@ -1075,7 +1087,7 @@ wget_wch_test(unsigned level, WINDOW *win, int delay) for (;;) { while ((code = wGet_wchar(win, &c)) == ERR) { incount++; - if (blocking) { + if (blocking_getch(flags, delay)) { (void) wprintw(win, "%05d: input error", incount); break; } else { @@ -1083,7 +1095,7 @@ wget_wch_test(unsigned level, WINDOW *win, int delay) } wgetch_wrap(win, first_y); } - if (code == ERR && blocking) { + if (code == ERR && blocking_getch(flags, delay)) { wprintw(win, "ERR"); wgetch_wrap(win, first_y); } else if (isQuit((int) c)) { @@ -1125,6 +1137,10 @@ wget_wch_test(unsigned level, WINDOW *win, int delay) wgetch_help(win, flags); } else if (c == 's') { ShellOut(TRUE); + } else if (c == 't') { + notimeout(win, flags[UChar('t')]); + flags[UChar('t')] = !flags[UChar('t')]; + wgetch_help(win, flags); } else if (c == 'w') { int high = getmaxy(win) - 1 - first_y + 1; int wide = getmaxx(win) - first_x; @@ -1184,7 +1200,7 @@ wget_wch_test(unsigned level, WINDOW *win, int delay) wtimeout(win, -1); if (!level) - init_getch(win, flags); + init_getch(win, flags, delay); } static void @@ -1252,8 +1268,14 @@ my_termattrs(void) #define termattrs() my_termattrs() #endif -#define MAX_ATTRSTRING 31 -#define LEN_ATTRSTRING 26 +#define ATTRSTRING_1ST 32 /* ' ' */ +#define ATTRSTRING_END 126 /* '~' */ + +#define COLS_PRE_ATTRS 5 +#define COLS_AFT_ATTRS 15 +#define COL_ATTRSTRING (COLS_PRE_ATTRS + 17) +#define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS)) +#define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST) static char attr_test_string[MAX_ATTRSTRING + 1]; @@ -1287,6 +1309,10 @@ attr_legend(WINDOW *helpwin) " a/A toggle ACS (alternate character set) mapping"); MvWPrintw(helpwin, row, col, " v/V toggle video attribute to combine with each line"); +#if USE_WIDEC_SUPPORT + MvWPrintw(helpwin, row, col, + " w/W toggle normal/wide (double-width) test-characters"); +#endif } static void @@ -1352,12 +1378,14 @@ cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR static void adjust_attr_string(int adjust) { - int first = ((int) UChar(attr_test_string[0])) + adjust; - int last = first + LEN_ATTRSTRING; + char save = attr_test_string[0]; + int first = ((int) UChar(save)) + adjust; + int j, k; - if (first >= ' ' && last <= '~') { /* 32..126 */ - int j, k; - for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) { + if (first >= ATTRSTRING_1ST) { + for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) { + if (k > ATTRSTRING_END) + break; attr_test_string[j] = (char) k; if (((k + 1 - first) % 5) == 0) { if (++j >= MAX_ATTRSTRING) @@ -1365,31 +1393,48 @@ adjust_attr_string(int adjust) attr_test_string[j] = ' '; } } - while (j < MAX_ATTRSTRING) - attr_test_string[j++] = ' '; - attr_test_string[j] = '\0'; - } else { - beep(); + if ((LEN_ATTRSTRING - j) > 5) { + attr_test_string[0] = save; + adjust_attr_string(adjust - 1); + } else { + while (j < MAX_ATTRSTRING) + attr_test_string[j++] = ' '; + attr_test_string[j] = '\0'; + } } } +/* + * Prefer the right-end of the string for starting, since that maps to the + * VT100 line-drawing. + */ +static int +default_attr_string(void) +{ + int result = (ATTRSTRING_END - LEN_ATTRSTRING); + result += (LEN_ATTRSTRING / 5); + if (result < ATTRSTRING_1ST) + result = ATTRSTRING_1ST; + return result; +} + static void init_attr_string(void) { - attr_test_string[0] = 'a'; + attr_test_string[0] = (char) default_attr_string(); adjust_attr_string(0); } static int -show_attr(int row, int skip, bool arrow, chtype attr, const char *name) +show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name) { int ncv = get_ncv(); - chtype test = attr & (chtype) (~A_ALTCHARSET); + chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT)); if (arrow) - MvPrintw(row, 5, "-->"); - MvPrintw(row, 8, "%s mode:", name); - MvPrintw(row, 24, "|"); + MvPrintw(row, COLS_PRE_ATTRS - 3, "-->"); + MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name); + MvPrintw(row, COL_ATTRSTRING - 1, "|"); if (skip) printw("%*s", skip, " "); /* @@ -1397,22 +1442,24 @@ show_attr(int row, int skip, bool arrow, chtype attr, const char *name) * character at a time (to pass its rendition directly), and use the * string operation for the other attributes. */ + wmove(win, 0, 0); + werase(win); if (attr & A_ALTCHARSET) { const char *s; chtype ch; for (s = attr_test_string; *s != '\0'; ++s) { ch = UChar(*s); - addch(ch | attr); + (void) waddch(win, ch | attr); } } else { - (void) attrset(attr); - addstr(attr_test_string); - attroff(attr); + (void) wattrset(win, AttrArg(attr, 0)); + (void) waddstr(win, attr_test_string); + (void) wattroff(win, (int) attr); } if (skip) printw("%*s", skip, " "); - printw("|"); + MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|"); if (test != A_NORMAL) { if (!(termattrs() & test)) { printw(" (N/A)"); @@ -1447,8 +1494,9 @@ show_attr(int row, int skip, bool arrow, chtype attr, const char *name) if (found) printw(" (NCV)"); } - if ((termattrs() & test) != test) + if ((termattrs() & test) != test) { printw(" (Part)"); + } } } return row + 2; @@ -1570,10 +1618,18 @@ attr_test(void) NCURSES_COLOR_T tx = -1; int ac = 0; unsigned j, k; + WINDOW *my_wins[SIZEOF(attrs_to_test)]; ATTR_TBL my_list[SIZEOF(attrs_to_test)]; unsigned my_size = init_attr_list(my_list, termattrs()); if (my_size > 1) { + for (j = 0; j < my_size; ++j) { + my_wins[j] = subwin(stdscr, + 1, LEN_ATTRSTRING, + 2 + (int) (2 * j), COL_ATTRSTRING); + scrollok(my_wins[j], FALSE); + } + if (skip < 0) skip = 0; @@ -1602,6 +1658,7 @@ attr_test(void) beep(); } else { extras |= (chtype) COLOR_PAIR(pair); + normal &= ~A_COLOR; } } } @@ -1614,17 +1671,18 @@ attr_test(void) for (j = 0; j < my_size; ++j) { bool arrow = (j == k); - row = show_attr(row, n, arrow, + row = show_attr(my_wins[j], row, n, arrow, + normal | extras | my_list[j].attr | my_list[k].attr, my_list[j].name); } - MvPrintw(row, 8, + MvPrintw(row, COLS_PRE_ATTRS, "This terminal does %shave the magic-cookie glitch", get_xmc() > -1 ? "" : "not "); - MvPrintw(row + 1, 8, "Enter '?' for help."); + MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help."); show_color_attr(fg, bg, tx); printw(" ACS (%d)", ac != 0); @@ -1640,36 +1698,81 @@ attr_test(void) } #if USE_WIDEC_SUPPORT +static bool use_fullwidth; static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1]; +#define FULL_LO 0xff00 +#define FULL_HI 0xff5e +#define HALF_LO 0x20 + +#define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI) +#define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO) +#define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO) + +/* + * Returns an ASCII code in [32..126] + */ +static wchar_t +normal_wchar(int ch) +{ + wchar_t result = (wchar_t) ch; + if (isFullWidth(ch)) + result = ToNormalWidth(ch); + return result; +} + +/* + * Returns either an ASCII code in in [32..126] or full-width in + * [0xff00..0xff5e], according to use_fullwidth setting. + */ +static wchar_t +target_wchar(int ch) +{ + wchar_t result = (wchar_t) ch; + if (use_fullwidth) { + if (!isFullWidth(ch)) + result = ToFullWidth(ch); + } else { + if (isFullWidth(ch)) + result = ToNormalWidth(ch); + } + return result; +} + static void wide_adjust_attr_string(int adjust) { - int first = ((int) UChar(wide_attr_test_string[0])) + adjust; - int last = first + LEN_ATTRSTRING; + wchar_t save = wide_attr_test_string[0]; + int first = ((int) normal_wchar(save)) + adjust; + int j, k; - if (first >= ' ' && last <= '~') { /* 32..126 */ - int j, k; - for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) { - wide_attr_test_string[j] = k; + if (first >= ATTRSTRING_1ST) { + for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) { + if (k > ATTRSTRING_END) + break; + wide_attr_test_string[j] = target_wchar(k); if (((k + 1 - first) % 5) == 0) { if (++j >= MAX_ATTRSTRING) break; wide_attr_test_string[j] = ' '; } } - while (j < MAX_ATTRSTRING) - wide_attr_test_string[j++] = ' '; - wide_attr_test_string[j] = '\0'; - } else { - beep(); + if ((LEN_ATTRSTRING - j) > 5) { + wide_attr_test_string[0] = save; + wide_adjust_attr_string(adjust - 1); + } else { + while (j < MAX_ATTRSTRING) + wide_attr_test_string[j++] = ' '; + wide_attr_test_string[j] = '\0'; + } } } static void wide_init_attr_string(void) { - wide_attr_test_string[0] = 'a'; + use_fullwidth = FALSE; + wide_attr_test_string[0] = (wchar_t) default_attr_string(); wide_adjust_attr_string(0); } @@ -1705,7 +1808,8 @@ get_wide_background(void) } static int -wide_show_attr(int row, +wide_show_attr(WINDOW *win, + int row, int skip, bool arrow, chtype attr, @@ -1716,9 +1820,9 @@ wide_show_attr(int row, chtype test = attr & ~WA_ALTCHARSET; if (arrow) - MvPrintw(row, 5, "-->"); - MvPrintw(row, 8, "%s mode:", name); - MvPrintw(row, 24, "|"); + MvPrintw(row, COLS_PRE_ATTRS - 3, "-->"); + MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name); + MvPrintw(row, COL_ATTRSTRING - 1, "|"); if (skip) printw("%*s", skip, " "); @@ -1727,6 +1831,8 @@ wide_show_attr(int row, * character at a time (to pass its rendition directly), and use the * string operation for the other attributes. */ + wmove(win, 0, 0); + werase(win); if (attr & WA_ALTCHARSET) { const wchar_t *s; cchar_t ch; @@ -1736,20 +1842,20 @@ wide_show_attr(int row, fill[0] = *s; fill[1] = L'\0'; setcchar(&ch, fill, attr, pair, 0); - add_wch(&ch); + (void) wadd_wch(win, &ch); } } else { attr_t old_attr = 0; NCURSES_PAIRS_T old_pair = 0; - (void) (attr_get) (&old_attr, &old_pair, 0); - (void) attr_set(attr, pair, 0); - addwstr(wide_attr_test_string); - (void) attr_set(old_attr, old_pair, 0); + (void) (wattr_get) (win, &old_attr, &old_pair, 0); + (void) wattr_set(win, attr, pair, 0); + (void) waddwstr(win, wide_attr_test_string); + (void) wattr_set(win, old_attr, old_pair, 0); } if (skip) printw("%*s", skip, " "); - printw("|"); + MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|"); if (test != A_NORMAL) { if (!(term_attrs() & test)) { printw(" (N/A)"); @@ -1779,8 +1885,9 @@ wide_show_attr(int row, if (found) printw(" (NCV)"); } - if ((term_attrs() & test) != test) + if ((term_attrs() & test) != test) { printw(" (Part)"); + } } } return row + 2; @@ -1832,6 +1939,14 @@ wide_attr_getc(int *skip, if (*kc >= limit) *kc = 0; break; + case 'w': + use_fullwidth = FALSE; + wide_adjust_attr_string(0); + break; + case 'W': + use_fullwidth = TRUE; + wide_adjust_attr_string(0); + break; case '<': wide_adjust_attr_string(-1); break; @@ -1862,9 +1977,17 @@ wide_attr_test(void) int ac = 0; unsigned j, k; ATTR_TBL my_list[SIZEOF(attrs_to_test)]; + WINDOW *my_wins[SIZEOF(attrs_to_test)]; unsigned my_size = init_attr_list(my_list, term_attrs()); if (my_size > 1) { + for (j = 0; j < my_size; ++j) { + my_wins[j] = subwin(stdscr, + 1, LEN_ATTRSTRING, + 2 + (int) (2 * j), COL_ATTRSTRING); + scrollok(my_wins[j], FALSE); + } + if (skip < 0) skip = 0; @@ -1900,7 +2023,7 @@ wide_attr_test(void) MvAddStr(0, 20, "Character attribute test display"); for (j = 0; j < my_size; ++j) { - row = wide_show_attr(row, n, j == k, + row = wide_show_attr(my_wins[j], row, n, (j == k), ((attr_t) ac | my_list[j].attr | my_list[k].attr), @@ -1908,10 +2031,10 @@ wide_attr_test(void) my_list[j].name); } - MvPrintw(row, 8, + MvPrintw(row, COLS_PRE_ATTRS, "This terminal does %shave the magic-cookie glitch", get_xmc() > -1 ? "" : "not "); - MvPrintw(row + 1, 8, "Enter '?' for help."); + MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help."); show_color_attr(fg, bg, tx); printw(" ACS (%d)", ac != 0); @@ -2062,9 +2185,10 @@ color_test(void) int page_size = (LINES - grid_top); int pairs_max; int colors_max = COLORS; + int col_limit; int row_limit; int per_row; - char numbered[80]; + char *numbered = 0; const char *hello; bool done = FALSE; bool opt_acsc = FALSE; @@ -2074,6 +2198,15 @@ color_test(void) bool opt_wide = FALSE; WINDOW *helpwin; + numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char)); + done = ((COLS < 16) || (numbered == 0)); + + /* + * Because the number of colors is usually a power of two, we also use + * a power of two for the number of colors shown per line (to be tidy). + */ + for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ; + while (!done) { int shown = 0; @@ -2091,11 +2224,11 @@ color_test(void) if (opt_wide) { width = 4; hello = "Test"; - per_row = (colors_max > 8) ? 16 : 8; + per_row = (col_limit / ((colors_max > 8) ? 4 : 8)); } else { width = 8; hello = "Hello"; - per_row = 8; + per_row = (col_limit / 8); } per_row -= min_colors; @@ -2126,6 +2259,9 @@ color_test(void) int col = (i % per_row + 1) * width; NCURSES_PAIRS_T pair = i; + if ((i / per_row) > row_limit) + break; + #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - min_colors)) + min_colors) #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - min_colors)) + min_colors) if (row >= 0 && move(row, col) != ERR) { @@ -2133,13 +2269,13 @@ color_test(void) NCURSES_COLOR_T bg = InxToBG(i); init_pair(pair, fg, bg); - attron((attr_t) COLOR_PAIR(pair)); + attron(COLOR_PAIR(pair)); if (opt_acsc) - attron((attr_t) A_ALTCHARSET); + attron(A_ALTCHARSET); if (opt_bold) - attron((attr_t) A_BOLD); + attron(A_BOLD); if (opt_revs) - attron((attr_t) A_REVERSE); + attron(A_REVERSE); if (opt_nums) { sprintf(numbered, "{%02X}", (int) i); @@ -2252,6 +2388,8 @@ color_test(void) erase(); endwin(); + + free(numbered); } #if USE_WIDEC_SUPPORT @@ -2266,9 +2404,10 @@ wide_color_test(void) int page_size = (LINES - grid_top); int pairs_max = (unsigned short) (-1); int colors_max = COLORS; + int col_limit; int row_limit; int per_row; - char numbered[80]; + char *numbered = 0; const char *hello; bool done = FALSE; bool opt_acsc = FALSE; @@ -2277,9 +2416,19 @@ wide_color_test(void) bool opt_wide = FALSE; bool opt_nums = FALSE; bool opt_xchr = FALSE; - wchar_t buffer[80]; + wchar_t *buffer = 0; WINDOW *helpwin; + numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char)); + buffer = (wchar_t *) calloc((size_t) (COLS + 1), sizeof(wchar_t)); + done = ((COLS < 16) || (numbered == 0) || (buffer == 0)); + + /* + * Because the number of colors is usually a power of two, we also use + * a power of two for the number of colors shown per line (to be tidy). + */ + for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ; + while (!done) { int shown = 0; @@ -2293,15 +2442,14 @@ wide_color_test(void) pairs_max = COLOR_PAIRS; } - /* this assumes an 80-column line */ if (opt_wide) { width = 4; hello = "Test"; - per_row = (colors_max > 8) ? 16 : 8; + per_row = (col_limit / ((colors_max > 8) ? 4 : 8)); } else { width = 8; hello = "Hello"; - per_row = 8; + per_row = (col_limit / 8); } per_row -= min_colors; @@ -2340,15 +2488,18 @@ wide_color_test(void) int col = (i % per_row + 1) * width; NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i; + if ((i / per_row) > row_limit) + break; + if (row >= 0 && move(row, col) != ERR) { init_pair(pair, InxToFG(i), InxToBG(i)); (void) color_set(pair, NULL); if (opt_acsc) - attr_on((attr_t) A_ALTCHARSET, NULL); + attr_on(A_ALTCHARSET, NULL); if (opt_bold) - attr_on((attr_t) A_BOLD, NULL); + attr_on(A_BOLD, NULL); if (opt_revs) - attr_on((attr_t) A_REVERSE, NULL); + attr_on(A_REVERSE, NULL); if (opt_nums) { sprintf(numbered, "{%02X}", i); @@ -2471,6 +2622,9 @@ wide_color_test(void) erase(); endwin(); + + free(numbered); + free(buffer); } #endif /* USE_WIDEC_SUPPORT */ @@ -2549,7 +2703,7 @@ color_edit(void) (i == current ? '>' : ' '), (i < (int) SIZEOF(the_color_names) ? the_color_names[i] : numeric)); - (void) attrset((attr_t) COLOR_PAIR(i)); + (void) attrset(AttrArg(COLOR_PAIR(i), 0)); addstr(" "); (void) attrset(A_NORMAL); @@ -3507,7 +3661,7 @@ show_paged_widechars(int base, MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last); attroff(A_BOLD); - for (code = first; (int) code <= last; code++) { + for (code = (wchar_t) first; (int) code <= last; code++) { int row = (2 + ((int) code - first) / per_line); int col = 5 * ((int) code % per_line); int count; @@ -3540,7 +3694,7 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIR MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last); attroff(A_BOLD); - for (code = first; (int) code <= last; code++) { + for (code = (wchar_t) first; (int) code <= last; code++) { int row = 2 + ((code - first) % 16); int col = ((code - first) / 16) * COLS / 2; wchar_t codes[10]; @@ -4752,13 +4906,13 @@ pflush(void) fill_panel(win) --------------------------------------------------------------------------*/ static void -init_panel(void) +init_panel(WINDOW *win) { register int y, x; for (y = 0; y < LINES - 1; y++) { for (x = 0; x < COLS; x++) - wprintw(stdscr, "%d", (y + x) % 10); + wprintw(win, "%d", (y + x) % 10); } } @@ -4784,7 +4938,7 @@ fill_panel(PANEL * pan) #if USE_WIDEC_SUPPORT static void -init_wide_panel(void) +init_wide_panel(WINDOW *win) { int digit; cchar_t temp[10]; @@ -4796,7 +4950,7 @@ init_wide_panel(void) int y, x; getyx(stdscr, y, x); digit = (y + x / 2) % 10; - } while (add_wch(&temp[digit]) != ERR); + } while (wadd_wch(win, &temp[digit]) != ERR); } static void @@ -4850,7 +5004,7 @@ canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd) } static void -demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *)) +demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *)) { int count; int itmp; @@ -4859,7 +5013,7 @@ demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *)) scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */ refresh(); - InitPanel(); + InitPanel(stdscr); for (count = 0; count < 5; count++) { px[1] = mkpanel(COLOR_RED, LINES / 2 - 2, @@ -5039,10 +5193,15 @@ panner_v_cleanup(int from_y, int from_x, int to_y) } static void -fill_pad(WINDOW *panpad, bool pan_lines) +fill_pad(WINDOW *panpad, bool pan_lines, bool colored) { int y, x; unsigned gridcount = 0; + chtype fill = 0; +#ifdef A_COLOR + if (colored) + fill = (chtype) COLOR_PAIR(1); +#endif wmove(panpad, 0, 0); for (y = 0; y < getmaxy(panpad); y++) { @@ -5056,7 +5215,7 @@ fill_pad(WINDOW *panpad, bool pan_lines) waddch(panpad, pan_lines ? ACS_LTEE : '+'); else waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') + - (int) (gridcount++ % 26))); + (int) (gridcount++ % 26)) | fill); } else if (y % GRIDSIZE == 0) waddch(panpad, pan_lines ? ACS_HLINE : '-'); else if (x % GRIDSIZE == 0) @@ -5070,7 +5229,8 @@ fill_pad(WINDOW *panpad, bool pan_lines) static void panner(WINDOW *pad, int top_x, int top_y, int porty, int portx, - int (*pgetc) (WINDOW *)) + int (*pgetc) (WINDOW *), + bool colored) { #if HAVE_GETTIMEOFDAY struct timeval before, after; @@ -5117,7 +5277,7 @@ panner(WINDOW *pad, break; case 'a': pan_lines = !pan_lines; - fill_pad(pad, pan_lines); + fill_pad(pad, pan_lines, colored); pending_pan = FALSE; break; @@ -5404,7 +5564,7 @@ padgetch(WINDOW *win) #define PAD_WIDE 200 static void -demo_pad(void) +demo_pad(bool colored) /* Demonstrate pads. */ { WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE); @@ -5413,8 +5573,14 @@ demo_pad(void) Cannot("cannot create requested pad"); return; } - - fill_pad(panpad, FALSE); +#ifdef A_COLOR + if (colored && use_colors) { + init_pair(1, COLOR_BLACK, COLOR_GREEN); + init_pair(2, COLOR_CYAN, COLOR_BLUE); + wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' ')); + } +#endif + fill_pad(panpad, FALSE, colored); panner_legend(LINES - 4); panner_legend(LINES - 3); @@ -5427,7 +5593,7 @@ demo_pad(void) * We'll still be able to widen it during a test, since that's required * for testing boundaries. */ - panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch); + panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, colored); delwin(panpad); endwin(); @@ -6305,11 +6471,11 @@ overlap_test_1_attr(WINDOW *win, int flavor, int col) break; case 2: init_pair(cpair, COLOR_BLUE, COLOR_WHITE); - (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_NORMAL)); + (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL)); break; case 3: init_pair(cpair, COLOR_WHITE, COLOR_BLUE); - (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_BOLD)); + (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD)); break; } } @@ -6691,7 +6857,11 @@ do_single_test(const char c) #endif case 'p': - demo_pad(); + demo_pad(FALSE); + break; + + case 'P': + demo_pad(TRUE); break; #if USE_LIBFORM @@ -6732,7 +6902,9 @@ usage(void) ," -a f,b set default-colors (assumed white-on-black)" ," -d use default-colors if terminal supports them" #endif +#if HAVE_USE_ENV ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS" +#endif #if USE_SOFTKEYS ," -e fmt specify format for soft-keys test (e)" #endif @@ -6845,6 +7017,7 @@ main_menu(bool top) #endif #endif (void) puts("p = exercise pad features"); + (void) puts("P = exercise pad features, using color"); (void) puts("q = quit"); #if USE_LIBFORM (void) puts("r = exercise forms code"); @@ -6952,9 +7125,11 @@ main(int argc, char *argv[]) default_colors = TRUE; break; #endif +#if HAVE_USE_ENV case 'E': use_env(FALSE); break; +#endif case 'e': my_e_param = atoi(optarg); #ifdef NCURSES_VERSION