Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
Thomas E. Dickey (beginning revision 1.27 in 1996).
-$Id: ncurses.c,v 1.309 2008/03/08 20:57:09 tom Exp $
+$Id: ncurses.c,v 1.312 2008/03/22 23:02:57 tom Exp $
***************************************************************************/
{
return ((c) == QUIT || (c) == ESCAPE);
}
-#define case_QUIT case QUIT: case ESCAPE
+#define case_QUIT QUIT: case ESCAPE
/* Common function to allow ^T to toggle trace-mode in the middle of a test
* so that trace-files can be made smaller.
}
#if USE_WIDEC_SUPPORT
+static wchar_t
+fullwidth_of(int ch)
+{
+ return (ch + 0xff10 - '0');
+}
+
+static void
+make_fullwidth_text(wchar_t *target, const char *source)
+{
+ int ch;
+ while ((ch = *source++) != 0) {
+ *target++ = fullwidth_of(ch);
+ }
+ *target = 0;
+}
+
+static void
+make_narrow_text(wchar_t *target, const char *source)
+{
+ int ch;
+ while ((ch = *source++) != 0) {
+ *target++ = ch;
+ }
+ *target = 0;
+}
+
+static void
+make_fullwidth_digit(cchar_t *target, int digit)
+{
+ wchar_t source[2];
+
+ source[0] = fullwidth_of(digit + '0');
+ source[1] = 0;
+ setcchar(target, source, A_NORMAL, 0, 0);
+}
+
static int
wGet_wchar(WINDOW *win, wint_t *result)
{
case '>':
adjust_attr_string(1);
break;
- case_QUIT:
+ case case_QUIT:
result = FALSE;
break;
default:
case '>':
wide_adjust_attr_string(1);
break;
- case_QUIT:
+ case case_QUIT:
result = FALSE;
break;
default:
}
static void
-color_legend(WINDOW *helpwin)
+color_legend(WINDOW *helpwin, bool wide)
{
int row = 1;
int col = 1;
mvwprintw(helpwin, row++, col,
"longer than one screen. Control/N and Control/P can be used");
mvwprintw(helpwin, row++, col,
- "in place up up/down arrow. Use pageup/pagedown to scroll a");
+ "in place of up/down arrow. Use pageup/pagedown to scroll a");
mvwprintw(helpwin, row++, col,
"full screen; control/B and control/F can be used here.");
++row;
mvwprintw(helpwin, row++, col,
"Toggles:");
+ mvwprintw(helpwin, row++, col,
+ " a/A toggle altcharset off/on");
mvwprintw(helpwin, row++, col,
" b/B toggle bold off/on");
mvwprintw(helpwin, row++, col,
" n/N toggle text/number on/off");
mvwprintw(helpwin, row++, col,
" w/W toggle width between 8/16 colors");
+#if USE_WIDEC_SUPPORT
+ if (wide) {
+ mvwprintw(helpwin, row++, col,
+ "Wide characters:");
+ mvwprintw(helpwin, row++, col,
+ " x/X toggle text between ASCII and wide-character");
+ }
+#else
+ (void) wide;
+#endif
}
#define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
char numbered[80];
const char *hello;
bool done = FALSE;
+ bool opt_acsc = FALSE;
bool opt_bold = FALSE;
bool opt_wide = FALSE;
bool opt_nums = FALSE;
init_pair(pair, fg, bg);
attron((attr_t) COLOR_PAIR(pair));
+ if (opt_acsc)
+ attron((attr_t) A_ALTCHARSET);
if (opt_bold)
attron((attr_t) A_BOLD);
}
switch (wGetchar(stdscr)) {
+ case 'a':
+ opt_acsc = FALSE;
+ break;
+ case 'A':
+ opt_acsc = TRUE;
+ break;
case 'b':
opt_bold = FALSE;
break;
case 'N':
opt_nums = TRUE;
break;
- case_QUIT:
+ case case_QUIT:
done = TRUE;
continue;
case 'w':
case '?':
if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
box(helpwin, 0, 0);
- color_legend(helpwin);
+ color_legend(helpwin, FALSE);
wGetchar(helpwin);
delwin(helpwin);
}
char numbered[80];
const char *hello;
bool done = FALSE;
+ bool opt_acsc = FALSE;
bool opt_bold = FALSE;
bool opt_wide = FALSE;
bool opt_nums = FALSE;
+ bool opt_xchr = FALSE;
+ wchar_t buffer[10];
WINDOW *helpwin;
while (!done) {
hello = "Hello";
per_row = 8;
}
+ if (opt_xchr) {
+ make_fullwidth_text(buffer, hello);
+ width *= 2;
+ per_row /= 2;
+ } else {
+ make_narrow_text(buffer, hello);
+ }
row_limit = (pairs_max + per_row - 1) / per_row;
if (row >= 0 && move(row, col) != ERR) {
init_pair(pair, i % COLORS, i / COLORS);
color_set(pair, NULL);
+ if (opt_acsc)
+ attr_on((attr_t) A_ALTCHARSET, NULL);
if (opt_bold)
attr_on((attr_t) A_BOLD, NULL);
if (opt_nums) {
sprintf(numbered, "{%02X}", i);
- hello = numbered;
+ if (opt_xchr) {
+ make_fullwidth_text(buffer, numbered);
+ } else {
+ make_narrow_text(buffer, numbered);
+ }
}
- printw("%-*.*s", width, width, hello);
+ addnwstr(buffer, width);
attr_set(A_NORMAL, 0, NULL);
if ((i % per_row) == 0 && (i % COLORS) == 0) {
}
switch (c = wGetchar(stdscr)) {
+ case 'a':
+ opt_acsc = FALSE;
+ break;
+ case 'A':
+ opt_acsc = TRUE;
+ break;
case 'b':
opt_bold = FALSE;
break;
case 'N':
opt_nums = TRUE;
break;
- case_QUIT:
+ case case_QUIT:
done = TRUE;
continue;
case 'w':
case 'W':
set_color_test(opt_wide, TRUE);
break;
+ case 'x':
+ opt_xchr = FALSE;
+ break;
+ case 'X':
+ opt_xchr = TRUE;
+ break;
case CTRL('p'):
case KEY_UP:
if (base_row <= 0) {
case '?':
if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
box(helpwin, 0, 0);
- color_legend(helpwin);
+ color_legend(helpwin, TRUE);
wGetchar(helpwin);
delwin(helpwin);
}
refresh();
break;
- case_QUIT:
+ case case_QUIT:
break;
default:
clrtobot();
break;
- case_QUIT:
+ case case_QUIT:
goto done;
#if HAVE_SLK_COLOR
clrtobot();
break;
- case_QUIT:
+ case case_QUIT:
goto done;
case 'F':
case KEY_RIGHT:
j++;
break;
- case_QUIT:
+ case case_QUIT:
return ((pair *) 0);
#ifdef NCURSES_MOUSE_VERSION
case KEY_MOUSE:
}
#if USE_WIDEC_SUPPORT
-static void
-make_fullwidth_digit(cchar_t *target, int digit)
-{
- wchar_t source[2];
-
- source[0] = digit + 0xff10;
- source[1] = 0;
- setcchar(target, source, A_NORMAL, 0, 0);
-}
-
static void
init_wide_panel(void)
{
c = KEY_DC;
break;
case ERR: /* FALLTHRU */
- case_QUIT:
+ case case_QUIT:
count = 0;
c = KEY_EXIT;
break;