Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
Thomas E. Dickey (beginning revision 1.27 in 1996).
-$Id: ncurses.c,v 1.347 2009/10/03 22:01:56 tom Exp $
+$Id: ncurses.c,v 1.350 2009/11/07 22:11:27 tom Exp $
***************************************************************************/
#if HAVE_WCSRTOMBS
#define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
#define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
-#define reset_wchars(state) memset(&state, 0, sizeof(state))
+#define reset_wchars(state) init_mb(state)
#elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
#define count_wchars(src, len, state) wcstombs(0, src, len)
#define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
-#define reset_wchars(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
+#define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
#define state_unused
#endif
#if HAVE_MBSRTOWCS
#define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
#define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
-#define reset_mbytes(state) memset(&state, 0, sizeof(state))
+#define reset_mbytes(state) init_mb(state)
#elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
#define count_mbytes(src, len, state) mbstowcs(0, src, len)
#define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
-#define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
+#define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
#define state_unused
#endif
,"[12345678] -- set label; labels are numbered 1 through 8"
,"e -- erase stdscr (should not erase labels)"
,"s -- test scrolling of shortened screen"
+ ,"v/V -- cycle through video attributes"
#if HAVE_SLK_COLOR
- ,"F/B -- cycle through foreground/background colors"
+ ,"F/f/B/b -- cycle through foreground/background colors"
#endif
,"ESC -- return to main menu"
,""
refresh();
}
+/****************************************************************************
+ *
+ * Alternate character-set stuff
+ *
+ ****************************************************************************/
+/* *INDENT-OFF* */
+static struct {
+ chtype attr;
+ const char *name;
+} attrs_to_cycle[] = {
+ { A_NORMAL, "normal" },
+ { A_BOLD, "bold" },
+ { A_BLINK, "blink" },
+ { A_REVERSE, "reverse" },
+ { A_UNDERLINE, "underline" },
+};
+/* *INDENT-ON* */
+
+static bool
+cycle_attr(int ch, unsigned *at_code, chtype *attr)
+{
+ bool result = TRUE;
+
+ switch (ch) {
+ case 'v':
+ if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
+ *at_code = 0;
+ break;
+ case 'V':
+ if (*at_code == 0)
+ *at_code = SIZEOF(attrs_to_cycle) - 1;
+ else
+ *at_code -= 1;
+ break;
+ default:
+ result = FALSE;
+ break;
+ }
+ if (result)
+ *attr = attrs_to_cycle[*at_code].attr;
+ return result;
+}
+
+static bool
+cycle_colors(int ch, int *fg, int *bg, short *pair)
+{
+ bool result = FALSE;
+
+ if (use_colors) {
+ result = TRUE;
+ switch (ch) {
+ case 'F':
+ if ((*fg -= 1) < 0)
+ *fg = COLORS - 1;
+ break;
+ case 'f':
+ if ((*fg += 1) >= COLORS)
+ *fg = 0;
+ break;
+ case 'B':
+ if ((*bg -= 1) < 0)
+ *bg = COLORS - 1;
+ break;
+ case 'b':
+ if ((*bg += 1) >= COLORS)
+ *bg = 0;
+ break;
+ default:
+ result = FALSE;
+ break;
+ }
+ if (result) {
+ *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
+ if (*pair != 0) {
+ *pair = 1;
+ if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
+ result = FALSE;
+ }
+ }
+ }
+ }
+ return result;
+}
+
#if HAVE_SLK_COLOR
static void
call_slk_color(short fg, short bg)
slk_color(1);
mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
clrtoeol();
+ slk_touch();
+ slk_noutrefresh();
refresh();
}
#endif
int c, fmt = 1;
char buf[9];
char *s;
+ chtype attr = A_NORMAL;
+ unsigned at_code = 0;
#if HAVE_SLK_COLOR
- short fg = COLOR_BLACK;
- short bg = COLOR_WHITE;
+ int fg = COLOR_BLACK;
+ int bg = COLOR_WHITE;
+ short pair = 0;
#endif
c = CTRL('l');
case case_QUIT:
goto done;
-#if HAVE_SLK_COLOR
- case 'F':
- if (use_colors) {
- fg = (short) ((fg + 1) % COLORS);
- call_slk_color(fg, bg);
- }
- break;
- case 'B':
- if (use_colors) {
- bg = (short) ((bg + 1) % COLORS);
- call_slk_color(fg, bg);
- }
- break;
-#endif
#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
case KEY_RESIZE:
wnoutrefresh(stdscr);
#endif
default:
+ if (cycle_attr(c, &at_code, &attr)) {
+ slk_attrset(attr);
+ slk_touch();
+ slk_noutrefresh();
+ break;
+ }
+#if HAVE_SLK_COLOR
+ if (cycle_colors(c, &fg, &bg, &pair)) {
+ if (use_colors) {
+ call_slk_color(fg, bg);
+ } else {
+ beep();
+ }
+ break;
+ }
+#endif
beep();
+ break;
}
} while (!isQuit(c = Getchar()));
int c, fmt = 1;
wchar_t buf[SLKLEN + 1];
char *s;
- short fg = COLOR_BLACK;
- short bg = COLOR_WHITE;
+ chtype attr = A_NORMAL;
+ unsigned at_code = 0;
+ int fg = COLOR_BLACK;
+ int bg = COLOR_WHITE;
+ short pair = 0;
c = CTRL('l');
if (use_colors) {
break;
#endif
default:
+ if (cycle_attr(c, &at_code, &attr)) {
+ slk_attr_set(attr, (fg || bg), NULL);
+ slk_touch();
+ slk_noutrefresh();
+ break;
+ }
+#if HAVE_SLK_COLOR
+ if (cycle_colors(c, &fg, &bg, &pair)) {
+ if (use_colors) {
+ call_slk_color(fg, bg);
+ } else {
+ beep();
+ }
+ break;
+ }
+#endif
beep();
+ break;
}
} while (!isQuit(c = Getchar()));
#endif
#endif /* SLK_INIT */
-/****************************************************************************
- *
- * Alternate character-set stuff
- *
- ****************************************************************************/
-/* *INDENT-OFF* */
-static struct {
- chtype attr;
- const char *name;
-} attrs_to_cycle[] = {
- { A_NORMAL, "normal" },
- { A_BOLD, "bold" },
- { A_BLINK, "blink" },
- { A_REVERSE, "reverse" },
- { A_UNDERLINE, "underline" },
-};
-/* *INDENT-ON* */
-
-static bool
-cycle_attr(int ch, unsigned *at_code, chtype *attr)
-{
- bool result = TRUE;
-
- switch (ch) {
- case 'v':
- if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
- *at_code = 0;
- break;
- case 'V':
- if (*at_code == 0)
- *at_code = SIZEOF(attrs_to_cycle) - 1;
- else
- *at_code -= 1;
- break;
- default:
- result = FALSE;
- break;
- }
- if (result)
- *attr = attrs_to_cycle[*at_code].attr;
- return result;
-}
-
-static bool
-cycle_colors(int ch, int *fg, int *bg, short *pair)
-{
- bool result = FALSE;
-
- if (use_colors) {
- result = TRUE;
- switch (ch) {
- case 'F':
- if ((*fg -= 1) < 0)
- *fg = COLORS - 1;
- break;
- case 'f':
- if ((*fg += 1) >= COLORS)
- *fg = 0;
- break;
- case 'B':
- if ((*bg -= 1) < 0)
- *bg = COLORS - 1;
- break;
- case 'b':
- if ((*bg += 1) >= COLORS)
- *bg = 0;
- break;
- default:
- result = FALSE;
- break;
- }
- if (result) {
- *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
- if (*pair != 0) {
- *pair = 1;
- if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
- result = FALSE;
- }
- }
- }
- }
- return result;
-}
-
/* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
* terminal to perform functions. The remaining codes can be graphic.
*/
wbkgd(win, A_REVERSE);
werase(win);
wmove(win, 0, 0);
- wprintw(win, "footer: window %p, %d columns", win, cols);
+ wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
wnoutrefresh(win);
return OK;
}
wbkgd(win, A_REVERSE);
werase(win);
wmove(win, 0, 0);
- wprintw(win, "header: window %p, %d columns", win, cols);
+ wprintw(win, "header: window %p, %d columns", (void *) win, cols);
wnoutrefresh(win);
return OK;
}