/****************************************************************************
- * 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 *
Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
Thomas E. Dickey (beginning revision 1.27 in 1996).
-$Id: ncurses.c,v 1.417 2014/10/10 09:09:41 tom Exp $
+$Id: ncurses.c,v 1.429 2016/01/03 01:50:10 tom Exp $
***************************************************************************/
}
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)
{
,"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"
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);
for (;;) {
while ((c = wGetchar(win)) == ERR) {
incount++;
- if (blocking) {
+ if (blocking_getch(flags, delay)) {
(void) wprintw(win, "%05d: input error", incount);
break;
} else {
}
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)) {
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;
wtimeout(win, -1);
if (!level)
- init_getch(win, flags);
+ init_getch(win, flags, delay);
}
static int
delay = -1;
}
raw();
- move(5, 0);
+ move(6, 0);
return 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);
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 {
}
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)) {
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;
wtimeout(win, -1);
if (!level)
- init_getch(win, flags);
+ init_getch(win, flags, delay);
}
static void
#define ATTRSTRING_1ST 32 /* ' ' */
#define ATTRSTRING_END 126 /* '~' */
-#define COL_ATTRSTRING 25
-#define MARGIN_4_ATTRS (COL_ATTRSTRING + 8)
-#define LEN_ATTRSTRING (COLS - MARGIN_4_ATTRS)
+#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];
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, COLS_PRE_ATTRS - 3, "-->");
+ MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
MvPrintw(row, COL_ATTRSTRING - 1, "|");
if (skip)
printw("%*s", skip, " ");
if (found)
printw(" (NCV)");
}
- if ((termattrs() & test) != test)
+ if ((termattrs() & test) != test) {
printw(" (Part)");
+ }
}
}
return row + 2;
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);
chtype test = attr & ~WA_ALTCHARSET;
if (arrow)
- MvPrintw(row, 5, "-->");
- MvPrintw(row, 8, "%s mode:", name);
+ MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
+ MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
MvPrintw(row, COL_ATTRSTRING - 1, "|");
if (skip)
printw("%*s", skip, " ");
if (found)
printw(" (NCV)");
}
- if ((term_attrs() & test) != test)
+ if ((term_attrs() & test) != test) {
printw(" (Part)");
+ }
}
}
return row + 2;
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);
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;
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;
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;
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) {
erase();
endwin();
+
+ free(numbered);
}
#if USE_WIDEC_SUPPORT
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;
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;
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;
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);
erase();
endwin();
+
+ free(numbered);
+ free(buffer);
}
#endif /* USE_WIDEC_SUPPORT */
}
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++) {
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)
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;
break;
case 'a':
pan_lines = !pan_lines;
- fill_pad(pad, pan_lines);
+ fill_pad(pad, pan_lines, colored);
pending_pan = FALSE;
break;
#define PAD_WIDE 200
static void
-demo_pad(void)
+demo_pad(bool colored)
/* Demonstrate pads. */
{
WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
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);
* 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();
#endif
case 'p':
- demo_pad();
+ demo_pad(FALSE);
+ break;
+
+ case 'P':
+ demo_pad(TRUE);
break;
#if USE_LIBFORM
#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");