X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fncurses.c;h=9a90d4018dc9fbdb740e2d9988d48cd15508fce3;hp=bb7f77c690541e80f8ab95824827e66da14818fb;hb=bcdff1f4b369c01b695ca2b73e9aaac54f9c4526;hpb=a0b91dc27f0c411e343161b0a4b5459d15a43f85 diff --git a/test/ncurses.c b/test/ncurses.c index bb7f77c6..9a90d401 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2014,2015 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.421 2015/10/24 23:32:57 tom Exp $ +$Id: ncurses.c,v 1.429 2016/01/03 01:50:10 tom Exp $ ***************************************************************************/ @@ -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 @@ -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 @@ -1413,7 +1429,7 @@ static int 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, COLS_PRE_ATTRS - 3, "-->"); @@ -1478,8 +1494,9 @@ show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *n if (found) printw(" (NCV)"); } - if ((termattrs() & test) != test) + if ((termattrs() & test) != test) { printw(" (Part)"); + } } } return row + 2; @@ -1868,8 +1885,9 @@ wide_show_attr(WINDOW *win, if (found) printw(" (NCV)"); } - if ((term_attrs() & test) != test) + if ((term_attrs() & test) != test) { printw(" (Part)"); + } } } return row + 2; @@ -2167,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; @@ -2179,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; @@ -2196,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; @@ -2231,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) { @@ -2357,6 +2388,8 @@ color_test(void) erase(); endwin(); + + free(numbered); } #if USE_WIDEC_SUPPORT @@ -2371,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; @@ -2382,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; @@ -2398,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; @@ -2445,6 +2488,9 @@ 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); @@ -2576,6 +2622,9 @@ wide_color_test(void) erase(); endwin(); + + free(numbered); + free(buffer); } #endif /* USE_WIDEC_SUPPORT */