X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fncurses.c;h=113b77d3db3fd9f2d65d198367fd71c801157320;hp=83586166a0377a5535eb459a8a733ab09566cef2;hb=a3754ea95eea6118bd49f0507f35a7ef15b41a6c;hpb=b040313679284c778b4f02a5b34d9e775ceba697 diff --git a/test/ncurses.c b/test/ncurses.c index 83586166..113b77d3 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. * + * Copyright (c) 1998-2011,2012 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.364 2011/01/15 23:45:49 tom Exp $ +$Id: ncurses.c,v 1.377 2012/09/08 23:58:58 tom Exp $ ***************************************************************************/ @@ -490,7 +490,7 @@ ShellOut(bool message) #ifdef __MINGW32__ system("cmd.exe"); #else - system("sh"); + IGNORE_RC(system("sh")); #endif if (message) addstr("returned from shellout.\n"); @@ -777,12 +777,21 @@ resize_boxes(unsigned level, WINDOW *win) } doupdate(); } -#endif /* resize_boxes */ +#endif /* resize_boxes */ #else #define forget_boxes() /* nothing */ #define remember_boxes(level,text,frame) /* nothing */ #endif +/* + * Return-code is OK/ERR or a keyname. + */ +static const char * +ok_keyname(int code) +{ + return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code))); +} + static void wgetch_test(unsigned level, WINDOW *win, int delay) { @@ -824,9 +833,11 @@ wgetch_test(unsigned level, WINDOW *win, int delay) } else if (c == 'g') { waddstr(win, "getstr test: "); echo(); - wgetnstr(win, buf, sizeof(buf) - 1); + c = wgetnstr(win, buf, sizeof(buf) - 1); noecho(); - wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf); + wprintw(win, "I saw %d characters:\n\t`%s' (%s).", + (int) strlen(buf), buf, + ok_keyname(c)); wclrtoeol(win); wgetch_wrap(win, first_y); } else if (c == 'k') { @@ -1394,7 +1405,7 @@ show_attr(int row, int skip, bool arrow, chtype attr, const char *name) if (!(termattrs() & test)) { printw(" (N/A)"); } else { - if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) { + if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) { static const chtype table[] = { A_STANDOUT, @@ -1675,8 +1686,8 @@ wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const cha add_wch(&ch); } } else { - attr_t old_attr; - short old_pair; + attr_t old_attr = 0; + short old_pair = 0; (void) attr_get(&old_attr, &old_pair, 0); (void) attr_set(attr, pair, 0); @@ -2972,7 +2983,7 @@ wide_slk_test(void) #endif default: if (cycle_attr(c, &at_code, &attr)) { - slk_attr_set(attr, (fg || bg), NULL); + slk_attr_set(attr, (short) (fg || bg), NULL); slk_touch(); slk_noutrefresh(); break; @@ -3000,15 +3011,46 @@ wide_slk_test(void) #endif #endif /* SLK_INIT */ -/* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the +static void +show_256_chars(int repeat, attr_t attr, short pair) +{ + unsigned first = 0; + unsigned last = 255; + unsigned code; + int count; + + erase(); + attron(A_BOLD); + MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x", + first, last); + attroff(A_BOLD); + refresh(); + + for (code = first; code <= last; ++code) { + int row = (int) (2 + (code / 16)); + int col = (int) (5 * (code % 16)); + mvaddch(row, col, colored_chtype(code, attr, pair)); + for (count = 1; count < repeat; ++count) { + addch(colored_chtype(code, attr, pair)); + } + } + +} + +/* + * Show a slice of 32 characters, allowing those to be repeated up to the + * screen's width. + * + * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the * terminal to perform functions. The remaining codes can be graphic. */ static void -show_upper_chars(unsigned first, int repeat, attr_t attr, short pair) +show_upper_chars(int base, int pagesize, int repeat, attr_t attr, short pair) { - bool C1 = (first == 128); unsigned code; - unsigned last = first + 31; + unsigned first = (unsigned) base; + unsigned last = first + (unsigned) pagesize - 2; + bool C1 = (first == 128); int reply; erase(); @@ -3020,8 +3062,8 @@ show_upper_chars(unsigned first, int repeat, attr_t attr, short pair) for (code = first; code <= last; code++) { int count = repeat; - int row = 2 + ((int) (code - first) % 16); - int col = ((int) (code - first) / 16) * COLS / 2; + int row = 2 + ((int) (code - first) % (pagesize / 2)); + int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2; char tmp[80]; sprintf(tmp, "%3u (0x%x)", code, code); MvPrintw(row, col, "%*s: ", COLS / 4, tmp); @@ -3195,6 +3237,7 @@ static void acs_display(void) { int c = 'a'; + int pagesize = 32; char *term = getenv("TERM"); const char *pch_kludge = ((term != 0 && strstr(term, "linux")) ? "p=PC, " @@ -3222,6 +3265,13 @@ acs_display(void) else beep(); break; + case 'w': + if (pagesize == 32) { + pagesize = 256; + } else { + pagesize = 32; + } + break; case 'x': ToggleAcs(last_show_acs, show_box_chars); break; @@ -3265,15 +3315,18 @@ acs_display(void) } break; } - if (last_show_acs != 0) + if (pagesize != 32) { + show_256_chars(repeat, attr, pair); + } else if (last_show_acs != 0) { last_show_acs(repeat, attr, pair); - else - show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair); + } else { + show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair); + } MvPrintw(LINES - 3, 0, "Note: ANSI terminals may not display C1 characters."); MvPrintw(LINES - 2, 0, - "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, repeat, ESC=quit", + "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, repeat, ESC=quit", pch_kludge); if (use_colors) { MvPrintw(LINES - 1, 0, @@ -3312,6 +3365,53 @@ merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair) return dst; } +/* + * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line + * display. If there are no repeats, we could normally display 16 lines of 64 + * characters (1024 total). However, taking repeats and double-width cells + * into account, use 256 characters for the page. + */ +static void +show_paged_widechars(int base, + int pagesize, + int repeat, + int space, + attr_t attr, + short pair) +{ + int first = base * pagesize; + int last = first + pagesize - 1; + int per_line = 16; + cchar_t temp; + wchar_t code; + wchar_t codes[10]; + + erase(); + attron(A_BOLD); + MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last); + attroff(A_BOLD); + + for (code = first; (int) code <= last; code++) { + int row = (2 + ((int) code - first) / per_line); + int col = 5 * ((int) code % per_line); + int count; + + memset(&codes, 0, sizeof(codes)); + codes[0] = code; + setcchar(&temp, codes, attr, pair, 0); + move(row, col); + if (wcwidth(code) == 0 && code != 0) { + addch((chtype) space | + (A_REVERSE ^ attr) | + (attr_t) COLOR_PAIR(pair)); + } + add_wch(&temp); + for (count = 1; count < repeat; ++count) { + add_wch(&temp); + } + } +} + static void show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair) { @@ -3332,11 +3432,13 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair) int count = repeat; int y, x; - memset(&codes, 0, sizeof(codes)); - codes[0] = code; sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code); MvPrintw(row, col, "%*s: ", COLS / 4, tmp); + + memset(&codes, 0, sizeof(codes)); + codes[0] = code; setcchar(&temp, codes, attr, pair, 0); + do { /* * Give non-spacing characters something to combine with. If we @@ -3350,16 +3452,17 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair) (attr_t) COLOR_PAIR(pair)); } /* - * This could use add_wch(), but is done for comparison with the - * normal 'f' test (and to make a test-case for echo_wchar()). - * The screen will flicker because the erase() at the top of the - * function is met by the builtin refresh() in echo_wchar(). + * This uses echo_wchar(), for comparison with the normal 'f' + * test (and to make a test-case for echo_wchar()). The screen + * may flicker because the erase() at the top of the function + * is met by the builtin refresh() in echo_wchar(). */ echo_wchar(&temp); /* * The repeat-count may make text wrap - avoid that. */ getyx(stdscr, y, x); + (void) y; if (x >= col + (COLS / 2) - 2) break; } while (--count > 0); @@ -3680,6 +3783,7 @@ wide_acs_display(void) int digit = 0; int repeat = 1; int space = ' '; + int pagesize = 32; chtype attr = A_NORMAL; int fg = COLOR_BLACK; int bg = COLOR_BLACK; @@ -3705,6 +3809,13 @@ wide_acs_display(void) ToggleAcs(last_show_wacs, show_wacs_chars_thick); break; #endif + case 'w': + if (pagesize == 32) { + pagesize = 256; + } else { + pagesize = 32; + } + break; case 'x': ToggleAcs(last_show_wacs, show_wbox_chars); break; @@ -3738,20 +3849,25 @@ wide_acs_display(void) } break; } - if (last_show_wacs != 0) + if (pagesize != 32) { + show_paged_widechars(digit, pagesize, repeat, space, attr, pair); + } else if (last_show_wacs != 0) { last_show_wacs(repeat, attr, pair); - else + } else { show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair); + } - MvPrintw(LINES - 3, 0, - "Select: a/d/t WACS, x box, u UTF-8, 0-9,+/- non-ASCII, repeat, ESC=quit"); + MvPrintw(LINES - 4, 0, + "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint"); + MvPrintw(LINES - 3, 2, + "0-9,+/- non-ASCII, repeat, _ space, ESC=quit"); if (use_colors) { - MvPrintw(LINES - 2, 0, + MvPrintw(LINES - 2, 2, "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.", attrs_to_cycle[at_code].name, fg, bg); } else { - MvPrintw(LINES - 2, 0, + MvPrintw(LINES - 2, 2, "v/V cycles through video attributes (%s).", attrs_to_cycle[at_code].name); } @@ -4269,8 +4385,10 @@ acs_and_scroll(void) neww->next = current ? current->next : 0; neww->last = current; - neww->last->next = neww; - neww->next->last = neww; + if (neww->last != 0) + neww->last->next = neww; + if (neww->next != 0) + neww->next->last = neww; neww->wind = getwin(fp); @@ -5226,7 +5344,7 @@ flushinp_test(WINDOW *win) #ifdef A_COLOR if (use_colors) { init_pair(2, COLOR_CYAN, COLOR_BLUE); - wbkgd(subWin, COLOR_PAIR(2) | ' '); + wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' ')); } #endif (void) wattrset(subWin, A_BOLD); @@ -6056,11 +6174,11 @@ overlap_test_1_attr(WINDOW *win, int flavor, int col) break; case 2: init_pair(cpair, COLOR_BLUE, COLOR_WHITE); - (void) wattrset(win, (attr_t) COLOR_PAIR(cpair) | A_NORMAL); + (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_NORMAL)); break; case 3: init_pair(cpair, COLOR_WHITE, COLOR_BLUE); - (void) wattrset(win, (attr_t) COLOR_PAIR(cpair) | A_BOLD); + (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_BOLD)); break; } } @@ -6483,6 +6601,7 @@ usage(void) ," -a f,b set default-colors (assumed white-on-black)" ," -d use default-colors if terminal supports them" #endif + ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS" #if USE_SOFTKEYS ," -e fmt specify format for soft-keys test (e)" #endif @@ -6495,6 +6614,9 @@ usage(void) #if USE_LIBPANEL ," -s msec specify nominal time for panel-demo (default: 1, to hold)" #endif +#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) + ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment" +#endif #ifdef TRACE ," -t mask specify default trace-level (may toggle with ^T)" #endif @@ -6681,7 +6803,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) { + while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:")) != -1) { switch (c) { #ifdef NCURSES_VERSION case 'a': @@ -6692,6 +6814,9 @@ main(int argc, char *argv[]) default_colors = TRUE; break; #endif + case 'E': + use_env(FALSE); + break; case 'e': my_e_param = atoi(optarg); #ifdef NCURSES_VERSION @@ -6721,6 +6846,11 @@ main(int argc, char *argv[]) nap_msec = (int) atol(optarg); break; #endif +#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) + case 'T': + use_tioctl(TRUE); + break; +#endif #ifdef TRACE case 't': save_trace = (unsigned) strtol(optarg, 0, 0); @@ -6772,7 +6902,7 @@ main(int argc, char *argv[]) use_default_colors(); min_colors = -1; } -#if NCURSES_VERSION_PATCH >= 20000708 +#if HAVE_ASSUME_DEFAULT_COLORS if (assumed_colors) assume_default_colors(default_fg, default_bg); #endif