+ "Select: a=ACS, x=box, %s0=C1, 1,2,3=GR characters, ESC=quit",
+ pch_kludge);
+ refresh();
+ } while (!isQuit(c = Getchar()));
+
+ Pause();
+ erase();
+ endwin();
+}
+
+#if USE_WIDEC_SUPPORT
+static cchar_t *
+merge_wide_attr(cchar_t *dst, cchar_t *src, attr_t attr, short pair)
+{
+ int count = getcchar(src, NULL, NULL, NULL, 0);
+ wchar_t *wch = 0;
+ attr_t ignore_attr;
+ short ignore_pair;
+
+ *dst = *src;
+ if (count > 0) {
+ if ((wch = typeMalloc(wchar_t, count)) != 0) {
+ if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
+ attr |= (ignore_attr & A_ALTCHARSET);
+ setcchar(dst, wch, attr, pair, 0);
+ }
+ free(wch);
+ }
+ }
+ return dst;
+}
+
+static void
+show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
+{
+ cchar_t temp;
+ wchar_t code;
+ int last = first + 31;
+
+ erase();
+ attron(A_BOLD);
+ mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
+ attroff(A_BOLD);
+
+ for (code = first; code <= last; code++) {
+ int row = 2 + ((code - first) % 16);
+ int col = ((code - first) / 16) * COLS / 2;
+ wchar_t codes[10];
+ char tmp[80];
+ 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);
+ setcchar(&temp, codes, attr, pair, 0);
+ do {
+ /*
+ * Give non-spacing characters something to combine with. If we
+ * don't, they'll bunch up in a heap on the space after the ":".
+ * Mark them with reverse-video to make them simpler to find on
+ * the display.
+ */
+ if (wcwidth(code) == 0)
+ addch(space | A_REVERSE);
+ /*
+ * 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().
+ */
+ echo_wchar(&temp);
+ /*
+ * The repeat-count may make text wrap - avoid that.
+ */
+ getyx(stdscr, y, x);
+ if (x >= col + (COLS / 2) - 2)
+ break;
+ } while (--count > 0);
+ }
+}
+
+static int
+show_1_wacs(int n, const char *name, const cchar_t *code)
+{
+ const int height = 16;
+ int row = 2 + (n % height);
+ int col = (n / height) * COLS / 2;
+ mvprintw(row, col, "%*s : ", COLS / 4, name);
+ add_wchnstr(code, 1);
+ return n + 1;
+}
+
+#define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
+
+static void
+show_wacs_chars(attr_t attr, short pair)
+/* display the wide-ACS character set */
+{
+ cchar_t temp;
+
+ int n;
+
+/*#define BOTH2(name) #name, &(name) */
+#define BOTH2(name) #name, MERGE_ATTR(name)
+
+ erase();
+ attron(A_BOLD);
+ mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
+ attroff(A_BOLD);
+ refresh();
+
+ n = show_1_wacs(0, BOTH2(WACS_ULCORNER));
+ n = show_1_wacs(n, BOTH2(WACS_URCORNER));
+ n = show_1_wacs(n, BOTH2(WACS_LLCORNER));
+ n = show_1_wacs(n, BOTH2(WACS_LRCORNER));
+
+ n = show_1_wacs(n, BOTH2(WACS_LTEE));
+ n = show_1_wacs(n, BOTH2(WACS_RTEE));
+ n = show_1_wacs(n, BOTH2(WACS_TTEE));
+ n = show_1_wacs(n, BOTH2(WACS_BTEE));
+
+ n = show_1_wacs(n, BOTH2(WACS_HLINE));
+ n = show_1_wacs(n, BOTH2(WACS_VLINE));
+
+ n = show_1_wacs(n, BOTH2(WACS_LARROW));
+ n = show_1_wacs(n, BOTH2(WACS_RARROW));
+ n = show_1_wacs(n, BOTH2(WACS_UARROW));
+ n = show_1_wacs(n, BOTH2(WACS_DARROW));
+
+ n = show_1_wacs(n, BOTH2(WACS_BLOCK));
+ n = show_1_wacs(n, BOTH2(WACS_BOARD));
+ n = show_1_wacs(n, BOTH2(WACS_LANTERN));
+ n = show_1_wacs(n, BOTH2(WACS_BULLET));
+ n = show_1_wacs(n, BOTH2(WACS_CKBOARD));
+ n = show_1_wacs(n, BOTH2(WACS_DEGREE));
+ n = show_1_wacs(n, BOTH2(WACS_DIAMOND));
+ n = show_1_wacs(n, BOTH2(WACS_PLMINUS));
+ n = show_1_wacs(n, BOTH2(WACS_PLUS));
+
+#ifdef CURSES_WACS_ARRAY
+ n = show_1_wacs(n, BOTH2(WACS_GEQUAL));
+ n = show_1_wacs(n, BOTH2(WACS_NEQUAL));
+ n = show_1_wacs(n, BOTH2(WACS_LEQUAL));
+
+ n = show_1_wacs(n, BOTH2(WACS_STERLING));
+ n = show_1_wacs(n, BOTH2(WACS_PI));
+ n = show_1_wacs(n, BOTH2(WACS_S1));
+ n = show_1_wacs(n, BOTH2(WACS_S3));
+ n = show_1_wacs(n, BOTH2(WACS_S7));
+ n = show_1_wacs(n, BOTH2(WACS_S9));
+#endif
+}
+
+#undef MERGE_ATTR
+
+#define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
+
+static void
+show_wbox_chars(attr_t attr, short pair)
+{
+ cchar_t temp;
+
+ erase();
+ attron(A_BOLD);
+ mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
+ attroff(A_BOLD);
+ refresh();
+
+ attr_set(attr, pair, 0);
+ box_set(stdscr, 0, 0);
+ attr_set(A_NORMAL, 0, 0);
+ /* *INDENT-OFF* */
+ mvhline_set(LINES / 2, 0, MERGE_ATTR(WACS_HLINE), COLS);
+ mvvline_set(0, COLS / 2, MERGE_ATTR(WACS_VLINE), LINES);
+ mvadd_wch(0, COLS / 2, MERGE_ATTR(WACS_TTEE));
+ mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(WACS_PLUS));
+ mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(WACS_BTEE));
+ mvadd_wch(LINES / 2, 0, MERGE_ATTR(WACS_LTEE));
+ mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(WACS_RTEE));
+ /* *INDENT-ON* */
+
+}
+
+#undef MERGE_ATTR
+
+static int
+show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
+{
+ const int height = 16;
+ int row = 2 + (n % height);
+ int col = (n / height) * COLS / 2;
+ char temp[80];
+
+ mvprintw(row, col, "%*s : ", COLS / 4, name);
+ attr_set(attr, pair, 0);
+ addstr(strcpy(temp, code));
+ attr_set(A_NORMAL, 0, 0);
+ return n + 1;
+}
+
+#define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
+
+static void
+show_utf8_chars(attr_t attr, short pair)
+{
+ int n;
+
+ erase();
+ attron(A_BOLD);
+ mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
+ attroff(A_BOLD);
+ refresh();
+ /* *INDENT-OFF* */
+ n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
+ n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
+ n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
+ n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
+
+ n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
+ n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
+ n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
+ n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
+
+ n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
+ n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
+
+ n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
+ n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
+ n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
+ n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
+
+ n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
+ n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
+ n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
+ n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
+ n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
+ n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
+ n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
+ n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
+ n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
+ n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
+ n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
+ n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
+
+ n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
+ n = SHOW_UTF8(n, "WACS_PI", "\317\200");
+ n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
+ n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
+ n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
+ n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
+ /* *INDENT-ON* */
+
+}
+/* *INDENT-OFF* */
+static struct {
+ attr_t attr;
+ const char *name;
+} attrs_to_cycle[] = {
+ { A_NORMAL, "normal" },
+ { A_BOLD, "bold" },
+ { 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 == 1)
+ *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) < 0)
+ *bg = 0;
+ break;
+ default:
+ result = FALSE;
+ break;
+ }
+ if (result) {
+ *pair = (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
+ if (*pair != 0) {
+ *pair = 1;
+ if (init_pair(*pair, *fg, *bg) == ERR) {
+ result = FALSE;
+ }
+ }
+ }
+ }
+ return result;
+}
+
+/* display the wide-ACS character set */
+static void
+wide_acs_display(void)
+{
+ int c = 'a';
+ int digit = 0;
+ int repeat = 0;
+ int space = ' ';
+ chtype attr = A_NORMAL;
+ int fg = COLOR_BLACK;
+ int bg = COLOR_BLACK;
+ unsigned at_code = 0;
+ short pair = 0;
+ void (*last_show_wacs) (attr_t, short) = 0;
+
+ do {
+ switch (c) {
+ case CTRL('L'):
+ Repaint();
+ break;
+ case 'a':
+ last_show_wacs = show_wacs_chars;
+ break;
+ case 'x':
+ last_show_wacs = show_wbox_chars;
+ break;
+ case 'u':
+ last_show_wacs = show_utf8_chars;
+ break;
+ default:
+ if (c < 256 && isdigit(c)) {
+ digit = (c - '0');
+ } else if (c == '+') {
+ ++digit;
+ } else if (c == '-' && digit > 0) {
+ --digit;
+ } else if (c == '>' && repeat < (COLS / 4)) {
+ ++repeat;
+ } else if (c == '<' && repeat > 0) {
+ --repeat;
+ } else if (c == '_') {
+ space = (space == ' ') ? '_' : ' ';
+ } else if (cycle_attr(c, &at_code, &attr)
+ || cycle_colors(c, &fg, &bg, &pair)) {
+ if (last_show_wacs != 0)
+ break;
+ } else {
+ beep();
+ break;
+ }
+ last_show_wacs = 0;
+ show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
+ break;
+ }
+ if (last_show_wacs != 0)
+ last_show_wacs(attr, pair);
+
+ mvprintw(LINES - 3, 0,
+ "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
+ if (use_colors) {
+ mvprintw(LINES - 2, 0,
+ "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,
+ "v/V cycles through video attributes (%s).",
+ attrs_to_cycle[at_code].name);
+ }