+ if (found)
+ printw(" (NCV)");
+ }
+ if ((term_attrs() & test) != test) {
+ printw(" (Part)");
+ }
+ }
+ }
+ return row + 2;
+}
+
+static bool
+wide_attr_getc(int *skip,
+ NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
+ NCURSES_COLOR_T *tx, int *ac,
+ unsigned *kc, unsigned limit)
+{
+ bool result = TRUE;
+ bool error = FALSE;
+ WINDOW *helpwin;
+
+ do {
+ int ch = Getchar();
+
+ error = FALSE;
+ if (ch < 256 && isdigit(ch)) {
+ *skip = (ch - '0');
+ } else {
+ switch (ch) {
+ case CTRL('L'):
+ Repaint();
+ break;
+ case HELP_KEY_1:
+ if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
+ box_set(helpwin, 0, 0);
+ attr_legend(helpwin);
+ wGetchar(helpwin);
+ delwin(helpwin);
+ }
+ break;
+ case 'a':
+ *ac = 0;
+ break;
+ case 'A':
+ *ac = A_ALTCHARSET;
+ break;
+ case 'v':
+ if (*kc == 0)
+ *kc = limit - 1;
+ else
+ *kc -= 1;
+ break;
+ case 'V':
+ *kc += 1;
+ if (*kc >= limit)
+ *kc = 0;
+ break;
+ case 'w':
+ use_fullwidth = FALSE;
+ wide_adjust_attr_string(0);
+ break;
+ case 'W':
+ use_fullwidth = TRUE;
+ wide_adjust_attr_string(0);
+ break;
+ case '<':
+ wide_adjust_attr_string(-1);
+ break;
+ case '>':
+ wide_adjust_attr_string(1);
+ break;
+ case case_QUIT:
+ result = FALSE;
+ break;
+ default:
+ error = cycle_color_attr(ch, fg, bg, tx);
+ break;
+ }
+ }
+ } while (error);
+ return result;
+}
+
+static void
+wide_attr_test(void)
+/* test text attributes using wide-character calls */
+{
+ int n;
+ int skip = get_xmc();
+ NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
+ NCURSES_COLOR_T bg = COLOR_BLACK;
+ NCURSES_COLOR_T tx = -1;
+ int ac = 0;
+ unsigned j, k;
+ ATTR_TBL my_list[SIZEOF(attrs_to_test)];
+ WINDOW *my_wins[SIZEOF(attrs_to_test)];
+ unsigned my_size = init_attr_list(my_list, term_attrs());
+
+ if (my_size > 1) {
+ for (j = 0; j < my_size; ++j) {
+ my_wins[j] = subwin(stdscr,
+ 1, LEN_ATTRSTRING,
+ 2 + (int) (2 * j), COL_ATTRSTRING);
+ scrollok(my_wins[j], FALSE);
+ }
+
+ if (skip < 0)
+ skip = 0;
+
+ n = skip; /* make it easy */
+ k = my_size - 1;
+ wide_init_attr_string();
+
+ do {
+ int row = 2;
+ NCURSES_PAIRS_T pair = 0;
+ NCURSES_PAIRS_T extras = 0;
+
+ if (use_colors) {
+ pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
+ if (pair != 0) {
+ pair = 1;
+ if (init_pair(pair, fg, bg) == ERR) {
+ beep();
+ }
+ }
+ extras = pair;
+ if (tx >= 0) {
+ extras = 2;
+ if (init_pair(extras, tx, bg) == ERR) {
+ beep();
+ }
+ }
+ }
+ set_wide_background(pair);
+ erase();
+
+ box_set(stdscr, 0, 0);
+ MvAddStr(0, 20, "Character attribute test display");
+
+ for (j = 0; j < my_size; ++j) {
+ row = wide_show_attr(my_wins[j], row, n, (j == k),
+ ((attr_t) ac |
+ my_list[j].attr |
+ my_list[k].attr),
+ extras,
+ my_list[j].name);
+ }
+
+ MvPrintw(row, COLS_PRE_ATTRS,
+ "This terminal does %shave the magic-cookie glitch",
+ get_xmc() > -1 ? "" : "not ");
+ MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
+ show_color_attr(fg, bg, tx);
+ printw(" ACS (%d)", ac != 0);
+
+ refresh();
+ } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
+
+ set_wide_background(0);
+ erase();
+ endwin();
+ } else {
+ Cannot("does not support extended video attributes.");
+ }
+}
+#endif
+
+/****************************************************************************
+ *
+ * Color support tests
+ *
+ ****************************************************************************/
+
+static NCURSES_CONST char *the_color_names[] =
+{
+ "black",
+ "red",
+ "green",
+ "yellow",
+ "blue",
+ "magenta",
+ "cyan",
+ "white",
+ "BLACK",
+ "RED",
+ "GREEN",
+ "YELLOW",
+ "BLUE",
+ "MAGENTA",
+ "CYAN",
+ "WHITE"
+};
+
+static void
+show_color_name(int y, int x, int color, bool wide)
+{
+ if (move(y, x) != ERR) {
+ char temp[80];
+ int width = 8;
+
+ if (wide) {
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "%02d", color);
+ width = 4;
+ } else if (color >= 8) {
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "[%02d]", color);
+ } else if (color < 0) {
+ _nc_STRCPY(temp, "default", sizeof(temp));
+ } else {
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "%.*s", 16, the_color_names[color]);
+ }
+ printw("%-*.*s", width, width, temp);
+ }
+}
+
+static void
+color_legend(WINDOW *helpwin, bool wide)
+{
+ int row = 1;
+ int col = 1;
+
+ MvWPrintw(helpwin, row++, col,
+ "ESC to exit.");
+ ++row;
+ MvWPrintw(helpwin, row++, col,
+ "Use up/down arrow to scroll through the display if it is");
+ MvWPrintw(helpwin, row++, col,
+ "longer than one screen. Control/N and Control/P can be used");
+ MvWPrintw(helpwin, row++, col,
+ "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");
+ if (has_colors()) {
+ MvWPrintw(helpwin, row++, col,
+ " c/C cycle used-colors through 8,16,...,COLORS");
+ }
+ MvWPrintw(helpwin, row++, col,
+ " n/N toggle text/number on/off");
+ MvWPrintw(helpwin, row++, col,
+ " r/R toggle reverse 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; }
+
+static int
+color_cycle(int current, int step)
+{
+ int result = current;
+ if (step < 0) {
+ if (current <= 8) {
+ result = COLORS;
+ } else {
+ result = 8;
+ if ((result * 2) > COLORS) {
+ result = COLORS;
+ } else {
+ while ((result * 2) < current) {
+ result *= 2;
+ }
+ }
+ }
+ } else {
+ if (current >= COLORS) {
+ result = 8;
+ } else {
+ result *= 2;
+ }
+ if (result > COLORS)
+ result = COLORS;
+ }
+ return result;
+}
+
+/* generate a color test pattern */
+static void
+color_test(void)
+{
+ NCURSES_PAIRS_T i;
+ int top = 0, width;
+ int base_row = 0;
+ int grid_top = top + 3;
+ int page_size = (LINES - grid_top);
+ int pairs_max;
+ int colors_max = COLORS;
+ int col_limit;
+ int row_limit;
+ int per_row;
+ char *numbered = 0;
+ const char *hello;
+ bool done = FALSE;
+ bool opt_acsc = FALSE;
+ bool opt_bold = FALSE;
+ bool opt_revs = FALSE;
+ bool opt_nums = 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;
+
+ pairs_max = PAIR_NUMBER(A_COLOR) + 1;
+ if (colors_max * colors_max <= COLOR_PAIRS) {
+ int limit = (colors_max - min_colors) * (colors_max - min_colors);
+ if (pairs_max > limit)
+ pairs_max = limit;
+ } else {
+ if (pairs_max > COLOR_PAIRS)
+ pairs_max = COLOR_PAIRS;
+ }
+
+ /* this assumes an 80-column line */
+ if (opt_wide) {
+ width = 4;
+ hello = "Test";
+ per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
+ } else {
+ width = 8;
+ hello = "Hello";
+ per_row = (col_limit / 8);
+ }
+ per_row -= min_colors;
+
+ row_limit = (pairs_max + per_row - 1) / per_row;
+
+ move(0, 0);
+ (void) printw("There are %d color pairs and %d colors",
+ pairs_max, COLORS);
+ if (colors_max != COLORS)
+ (void) printw(" (using %d colors)", colors_max);
+ if (min_colors)
+ (void) addstr(" besides 'default'");
+
+ clrtobot();
+ MvPrintw(top + 1, 0,
+ "%dx%d matrix of foreground/background colors, bold *%s*\n",
+ row_limit,
+ per_row,
+ opt_bold ? "on" : "off");
+
+ /* show color names/numbers across the top */
+ for (i = 0; i < per_row; i++)
+ show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
+
+ /* show a grid of colors, with color names/ numbers on the left */
+ for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
+ int row = grid_top + (i / per_row) - base_row;
+ 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) {
+ NCURSES_COLOR_T fg = InxToFG(i);
+ NCURSES_COLOR_T bg = InxToBG(i);
+
+ init_pair(pair, fg, bg);
+ attron(COLOR_PAIR(pair));
+ if (opt_acsc)
+ attron(A_ALTCHARSET);
+ if (opt_bold)
+ attron(A_BOLD);
+ if (opt_revs)
+ attron(A_REVERSE);
+
+ if (opt_nums) {
+ _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
+ "{%02X}", (int) i);
+ hello = numbered;
+ }
+ printw("%-*.*s", width, width, hello);
+ (void) attrset(A_NORMAL);
+
+ if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
+ show_color_name(row, 0, InxToBG(i), opt_wide);
+ }
+ ++shown;
+ } else if (shown) {
+ break;
+ }
+ }
+
+ switch (wGetchar(stdscr)) {
+ case 'a':
+ opt_acsc = FALSE;
+ break;
+ case 'A':
+ opt_acsc = TRUE;
+ break;
+ case 'b':
+ opt_bold = FALSE;
+ break;
+ case 'B':
+ opt_bold = TRUE;
+ break;
+ case 'c':
+ colors_max = color_cycle(colors_max, -1);
+ break;
+ case 'C':
+ colors_max = color_cycle(colors_max, 1);
+ break;
+ case 'n':
+ opt_nums = FALSE;
+ break;
+ case 'N':
+ opt_nums = TRUE;
+ break;
+ case 'r':
+ opt_revs = FALSE;
+ break;
+ case 'R':
+ opt_revs = TRUE;
+ break;
+ case case_QUIT:
+ done = TRUE;
+ continue;
+ case 'w':
+ set_color_test(opt_wide, FALSE);
+ break;
+ case 'W':
+ set_color_test(opt_wide, TRUE);
+ break;
+ case CTRL('p'):
+ case KEY_UP:
+ if (base_row <= 0) {
+ beep();
+ } else {
+ base_row -= 1;
+ }
+ break;
+ case CTRL('n'):
+ case KEY_DOWN:
+ if (base_row + page_size >= row_limit) {
+ beep();
+ } else {
+ base_row += 1;
+ }
+ break;
+ case CTRL('b'):
+ case KEY_PREVIOUS:
+ case KEY_PPAGE:
+ if (base_row <= 0) {
+ beep();
+ } else {
+ base_row -= (page_size - 1);
+ if (base_row < 0)
+ base_row = 0;
+ }
+ break;
+ case CTRL('f'):
+ case KEY_NEXT:
+ case KEY_NPAGE:
+ if (base_row + page_size >= row_limit) {
+ beep();
+ } else {
+ base_row += page_size - 1;
+ if (base_row + page_size >= row_limit) {
+ base_row = row_limit - page_size - 1;
+ }
+ }
+ break;
+ case HELP_KEY_1:
+ if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
+ box(helpwin, 0, 0);
+ color_legend(helpwin, FALSE);
+ wGetchar(helpwin);
+ delwin(helpwin);
+ }
+ break;
+ default:
+ beep();
+ continue;
+ }
+ }
+
+ erase();
+ endwin();
+
+ free(numbered);
+}
+
+#if USE_WIDEC_SUPPORT
+/* generate a color test pattern */
+static void
+wide_color_test(void)
+{
+ int i;
+ int top = 0, width;
+ int base_row = 0;
+ int grid_top = top + 3;
+ 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 = 0;
+ const char *hello;
+ bool done = FALSE;
+ bool opt_acsc = FALSE;
+ bool opt_bold = FALSE;
+ bool opt_revs = FALSE;
+ bool opt_wide = FALSE;
+ bool opt_nums = FALSE;
+ bool opt_xchr = FALSE;
+ 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 = (unsigned short) (-1);
+ if (colors_max * colors_max <= COLOR_PAIRS) {
+ int limit = (colors_max - min_colors) * (colors_max - min_colors);
+ if (pairs_max > limit)
+ pairs_max = limit;
+ } else {
+ if (pairs_max > COLOR_PAIRS)
+ pairs_max = COLOR_PAIRS;
+ }
+
+ if (opt_wide) {
+ width = 4;
+ hello = "Test";
+ per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
+ } else {
+ width = 8;
+ hello = "Hello";
+ per_row = (col_limit / 8);
+ }
+ per_row -= min_colors;
+
+ 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;
+
+ move(0, 0);
+ (void) printw("There are %d color pairs and %d colors",
+ pairs_max, COLORS);
+ if (colors_max != COLORS)
+ (void) printw(" (using %d colors)", colors_max);
+ if (min_colors)
+ (void) addstr(" besides 'default'");
+
+ clrtobot();
+ MvPrintw(top + 1, 0,
+ "%dx%d matrix of foreground/background colors, bold *%s*\n",
+ row_limit,
+ per_row,
+ opt_bold ? "on" : "off");
+
+ /* show color names/numbers across the top */
+ for (i = 0; i < per_row; i++)
+ show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
+
+ /* show a grid of colors, with color names/ numbers on the left */
+ for (i = (base_row * per_row); i < pairs_max; i++) {
+ int row = grid_top + (i / per_row) - base_row;
+ 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);
+ if (opt_acsc)
+ attr_on(A_ALTCHARSET, NULL);
+ if (opt_bold)
+ attr_on(A_BOLD, NULL);
+ if (opt_revs)
+ attr_on(A_REVERSE, NULL);
+
+ if (opt_nums) {
+ _nc_SPRINTF(numbered,
+ _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
+ "{%02X}", i);
+ if (opt_xchr) {
+ make_fullwidth_text(buffer, numbered);
+ } else {
+ make_narrow_text(buffer, numbered);
+ }
+ }
+ addnwstr(buffer, width);
+ (void) attr_set(A_NORMAL, 0, NULL);
+
+ if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
+ show_color_name(row, 0, InxToBG(i), opt_wide);
+ }
+ ++shown;
+ } else if (shown) {
+ break;
+ }
+ }
+
+ switch (wGetchar(stdscr)) {
+ case 'a':
+ opt_acsc = FALSE;
+ break;
+ case 'A':
+ opt_acsc = TRUE;
+ break;
+ case 'b':
+ opt_bold = FALSE;
+ break;
+ case 'B':
+ opt_bold = TRUE;
+ break;
+ case 'c':
+ colors_max = color_cycle(colors_max, -1);
+ break;
+ case 'C':
+ colors_max = color_cycle(colors_max, 1);
+ break;
+ case 'n':
+ opt_nums = FALSE;
+ break;
+ case 'N':
+ opt_nums = TRUE;
+ break;
+ case 'r':
+ opt_revs = FALSE;
+ break;
+ case 'R':
+ opt_revs = TRUE;
+ break;
+ case case_QUIT:
+ done = TRUE;
+ continue;
+ case 'w':
+ set_color_test(opt_wide, FALSE);
+ break;
+ 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) {
+ beep();
+ } else {
+ base_row -= 1;
+ }
+ break;
+ case CTRL('n'):
+ case KEY_DOWN:
+ if (base_row + page_size >= row_limit) {
+ beep();
+ } else {
+ base_row += 1;
+ }
+ break;
+ case CTRL('b'):
+ case KEY_PREVIOUS:
+ case KEY_PPAGE:
+ if (base_row <= 0) {
+ beep();
+ } else {
+ base_row -= (page_size - 1);
+ if (base_row < 0)
+ base_row = 0;
+ }
+ break;
+ case CTRL('f'):
+ case KEY_NEXT:
+ case KEY_NPAGE:
+ if (base_row + page_size >= row_limit) {
+ beep();
+ } else {
+ base_row += page_size - 1;
+ if (base_row + page_size >= row_limit) {
+ base_row = row_limit - page_size - 1;
+ }
+ }
+ break;
+ case HELP_KEY_1:
+ if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
+ box(helpwin, 0, 0);
+ color_legend(helpwin, TRUE);
+ wGetchar(helpwin);
+ delwin(helpwin);
+ }
+ break;
+ default:
+ beep();
+ continue;
+ }
+ }
+
+ erase();
+ endwin();
+
+ free(numbered);
+ free(buffer);
+}
+#endif /* USE_WIDEC_SUPPORT */
+
+static void
+change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
+{
+ NCURSES_COLOR_T red, green, blue;
+
+ color_content(current, &red, &green, &blue);
+
+ switch (field) {
+ case 0:
+ red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
+ break;
+ case 1:
+ green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
+ break;
+ case 2:
+ blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
+ break;
+ }
+
+ if (init_color(current, red, green, blue) == ERR)
+ beep();
+}
+
+static void
+reset_all_colors(void)
+{
+ NCURSES_PAIRS_T c;
+
+ for (c = 0; c < COLORS; ++c)
+ init_color(c,
+ all_colors[c].red,
+ all_colors[c].green,
+ all_colors[c].blue);
+}
+
+#define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
+#define okRGB(n) ((n) >= 0 && (n) <= 1000)
+#define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
+
+static void
+init_all_colors(bool xterm_colors, char *palette_file)
+{
+ NCURSES_PAIRS_T cp;
+ all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
+ if (!all_colors)
+ failed("all_colors");
+ for (cp = 0; cp < max_colors; ++cp) {
+ color_content(cp,
+ &all_colors[cp].red,
+ &all_colors[cp].green,
+ &all_colors[cp].blue);
+ }
+ /* xterm and compatible terminals can read results of an OSC string
+ * asking for the current color palette.
+ */
+ if (xterm_colors) {
+ int n;
+ int got;
+ char result[BUFSIZ];
+ int check_n;
+ unsigned check_r, check_g, check_b;
+
+ raw();
+ noecho();
+ for (n = 0; n < max_colors; ++n) {
+ fprintf(stderr, "\033]4;%d;?\007", n);
+ got = (int) read(0, result, sizeof(result) - 1);
+ if (got < 0)
+ break;
+ result[got] = '\0';
+ if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
+ &check_n,
+ &check_r,
+ &check_g,
+ &check_b) == 4 &&
+ check_n == n) {
+ all_colors[n].red = DecodeRGB(check_r);
+ all_colors[n].green = DecodeRGB(check_g);
+ all_colors[n].blue = DecodeRGB(check_b);
+ } else {
+ break;
+ }
+ }
+ reset_prog_mode();
+ }
+ if (palette_file != 0) {
+ FILE *fp = fopen(palette_file, "r");
+ if (fp != 0) {
+ char buffer[BUFSIZ];
+ int red, green, blue;
+ int scale = 1000;
+ int c;
+ while (fgets(buffer, sizeof(buffer), fp) != 0) {
+ if (sscanf(buffer, "scale:%d", &c) == 1) {
+ scale = c;
+ } else if (sscanf(buffer, "%d:%d %d %d",
+ &c,
+ &red,
+ &green,
+ &blue) == 4
+ && okCOLOR(c)
+ && okRGB(red)
+ && okRGB(green)
+ && okRGB(blue)) {
+#define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
+ all_colors[c].red = Scaled(red);
+ all_colors[c].green = Scaled(green);
+ all_colors[c].blue = Scaled(blue);
+ }
+ }
+ fclose(fp);
+ }
+ }
+}
+
+#define scaled_rgb(n) ((255 * (n)) / 1000)
+
+static void
+color_edit(void)
+/* display the color test pattern, without trying to edit colors */
+{
+ int i;
+ int current;
+ int this_c, value, field;
+ int last_c;
+ int top_color;
+ int page_size;
+
+ reset_all_colors();
+#ifdef KEY_RESIZE
+ retry:
+#endif
+ current = 0;
+ this_c = 0;
+ value = 0;
+ field = 0;
+ top_color = 0;
+ page_size = (LINES - 6);
+ erase();
+
+ for (i = 0; i < max_colors; i++)
+ init_pair((NCURSES_PAIRS_T) i,
+ (NCURSES_COLOR_T) COLOR_WHITE,
+ (NCURSES_COLOR_T) i);
+
+ MvPrintw(LINES - 2, 0, "Number: %d", value);
+
+ do {
+ NCURSES_COLOR_T red, green, blue;
+
+ attron(A_BOLD);
+ MvAddStr(0, 20, "Color RGB Value Editing");
+ attroff(A_BOLD);
+
+ for (i = (NCURSES_COLOR_T) top_color;
+ (i - top_color < page_size)
+ && (i < max_colors); i++) {
+ char numeric[80];
+
+ _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
+ MvPrintw(2 + i - top_color, 0, "%c %-8s:",
+ (i == current ? '>' : ' '),
+ (i < (int) SIZEOF(the_color_names)
+ ? the_color_names[i] : numeric));
+ (void) attrset(AttrArg(COLOR_PAIR(i), 0));
+ addstr(" ");
+ (void) attrset(A_NORMAL);
+
+ color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
+ addstr(" R = ");
+ if (current == i && field == 0)
+ attron(A_STANDOUT);
+ printw("%04d", (int) red);
+ if (current == i && field == 0)
+ (void) attrset(A_NORMAL);
+ addstr(", G = ");
+ if (current == i && field == 1)
+ attron(A_STANDOUT);
+ printw("%04d", (int) green);
+ if (current == i && field == 1)
+ (void) attrset(A_NORMAL);
+ addstr(", B = ");
+ if (current == i && field == 2)
+ attron(A_STANDOUT);
+ printw("%04d", (int) blue);
+ if (current == i && field == 2)
+ (void) attrset(A_NORMAL);
+ (void) attrset(A_NORMAL);
+ printw(" ( %3d %3d %3d )",
+ (int) scaled_rgb(red),
+ (int) scaled_rgb(green),
+ (int) scaled_rgb(blue));
+ }
+
+ MvAddStr(LINES - 3, 0,
+ "Use up/down to select a color, left/right to change fields.");
+ MvAddStr(LINES - 2, 0,
+ "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
+
+ move(2 + current - top_color, 0);
+
+ last_c = this_c;
+ this_c = Getchar();
+ if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
+ value = 0;
+
+ switch (this_c) {
+#ifdef KEY_RESIZE
+ case KEY_RESIZE:
+ move(0, 0);
+ goto retry;
+#endif
+ case '!':
+ ShellOut(FALSE);
+ /* FALLTHRU */
+ case CTRL('r'):
+ endwin();
+ refresh();
+ break;
+ case CTRL('l'):
+ refresh();
+ break;
+ case CTRL('b'):
+ case KEY_PPAGE:
+ if (current > 0)
+ current -= (page_size - 1);
+ else
+ beep();
+ break;
+
+ case CTRL('f'):
+ case KEY_NPAGE:
+ if (current < (max_colors - 1))
+ current += (page_size - 1);
+ else
+ beep();
+ break;
+
+ case CTRL('p'):
+ case KEY_UP:
+ current = (current == 0 ? (max_colors - 1) : current - 1);
+ break;
+
+ case CTRL('n'):
+ case KEY_DOWN:
+ current = (current == (max_colors - 1) ? 0 : current + 1);
+ break;
+
+ case '\t':
+ case KEY_RIGHT:
+ field = (field == 2 ? 0 : field + 1);
+ break;
+
+ case KEY_BTAB:
+ case KEY_LEFT:
+ field = (field == 0 ? 2 : field - 1);
+ break;
+
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ value = value * 10 + (this_c - '0');
+ break;
+
+ case '+':
+ change_color((NCURSES_PAIRS_T) current, field, value, 1);
+ break;
+
+ case '-':
+ change_color((NCURSES_PAIRS_T) current, field, -value, 1);
+ break;
+
+ case '=':
+ change_color((NCURSES_PAIRS_T) current, field, value, 0);
+ break;
+
+ case HELP_KEY_1:
+ erase();
+ P(" RGB Value Editing Help");
+ P("");
+ P("You are in the RGB value editor. Use the arrow keys to select one of");
+ P("the fields in one of the RGB triples of the current colors; the one");
+ P("currently selected will be reverse-video highlighted.");
+ P("");
+ P("To change a field, enter the digits of the new value; they are echoed");
+ P("as entered. Finish by typing `='. The change will take effect instantly.");
+ P("To increment or decrement a value, use the same procedure, but finish");
+ P("with a `+' or `-'.");
+ P("");
+ P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
+ P("");
+ P("Press 'm' to invoke the top-level menu with the current color settings.");
+ P("To quit, do ESC");
+
+ Pause();
+ erase();
+ break;
+
+ case 'm':
+ endwin();
+ main_menu(FALSE);
+ for (i = 0; i < max_colors; i++)
+ init_pair((NCURSES_PAIRS_T) i,
+ (NCURSES_COLOR_T) COLOR_WHITE,
+ (NCURSES_COLOR_T) i);
+ refresh();
+ break;
+
+ case case_QUIT:
+ break;
+
+ default:
+ beep();
+ break;
+ }
+
+ if (current < 0)
+ current = 0;
+ if (current >= max_colors)
+ current = max_colors - 1;
+ if (current < top_color)
+ top_color = current;
+ if (current - top_color >= page_size)
+ top_color = current - (page_size - 1);
+
+ MvPrintw(LINES - 1, 0, "Number: %d", value);
+ clrtoeol();
+ } while
+ (!isQuit(this_c, TRUE));
+
+ erase();
+
+ /*
+ * ncurses does not reset each color individually when calling endwin().
+ */
+ reset_all_colors();
+
+ endwin();
+}
+
+/****************************************************************************
+ *
+ * Alternate character-set stuff
+ *
+ ****************************************************************************/
+static bool
+cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
+{
+ bool result = TRUE;
+
+ switch (ch) {
+ case 'v':
+ if ((*at_code += 1) >= limit)
+ *at_code = 0;
+ break;
+ case 'V':
+ if (*at_code == 0)
+ *at_code = limit - 1;
+ else
+ *at_code -= 1;
+ break;
+ default:
+ result = FALSE;
+ break;
+ }
+ if (result)
+ *attr = list[*at_code].attr;
+ return result;
+}
+
+static bool
+cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *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 = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
+ if (*pair != 0) {
+ *pair = 1;
+ if (init_pair(*pair,
+ (NCURSES_COLOR_T) *fg,
+ (NCURSES_COLOR_T) *bg) == ERR) {
+ result = FALSE;
+ }
+ }
+ }
+ }
+ return result;
+}
+
+/****************************************************************************
+ *
+ * Soft-key label test
+ *
+ ****************************************************************************/
+
+#if USE_SOFTKEYS
+
+#define SLK_HELP 17
+#define SLK_WORK (SLK_HELP + 3)
+
+static void
+slk_help(void)
+{
+ static const char *table[] =
+ {
+ "Available commands are:"
+ ,""
+ ,"^L -- repaint this message and activate soft keys"
+ ,"a/d -- activate/disable soft keys"
+ ,"c -- set centered format for labels"
+ ,"l -- set left-justified format for labels"
+ ,"r -- set right-justified format for labels"
+ ,"[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/f/B/b -- cycle through foreground/background colors"
+#endif
+ ,"ESC -- return to main menu"
+ ,""
+ ,"Note: if activating the soft keys causes your terminal to scroll up"
+ ,"one line, your terminal auto-scrolls when anything is written to the"
+ ,"last screen position. The ncurses code does not yet handle this"
+ ,"gracefully."
+ };
+ unsigned j;
+
+ move(2, 0);
+ for (j = 0; j < SIZEOF(table); ++j) {
+ P(table[j]);
+ }
+ refresh();
+}
+
+#if HAVE_SLK_COLOR
+static void
+call_slk_color(int fg, int bg)
+{
+ init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
+ slk_color(1);
+ MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
+ clrtoeol();
+ slk_touch();
+ slk_noutrefresh();
+ refresh();
+}
+#endif
+
+static void
+slk_test(void)
+/* exercise the soft keys */
+{
+ int c, fmt = 1;
+ char buf[9];
+ char *s;
+ chtype attr = A_NORMAL;
+ unsigned at_code = 0;
+#if HAVE_SLK_COLOR
+ int fg = COLOR_BLACK;
+ int bg = COLOR_WHITE;
+ NCURSES_PAIRS_T pair = 0;
+#endif
+ ATTR_TBL my_list[SIZEOF(attrs_to_test)];
+ unsigned my_size = init_attr_list(my_list, termattrs());
+
+ c = CTRL('l');
+#if HAVE_SLK_COLOR
+ if (use_colors) {
+ call_slk_color(fg, bg);
+ }
+#endif
+
+ do {
+ move(0, 0);
+ switch (c) {
+ case CTRL('l'):
+ erase();
+ attron(A_BOLD);
+ MvAddStr(0, 20, "Soft Key Exerciser");
+ attroff(A_BOLD);
+
+ slk_help();
+ /* fall through */
+
+ case 'a':
+ slk_restore();
+ break;
+
+ case 'e':
+ wclear(stdscr);
+ break;
+
+ case 's':
+ MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
+ while ((c = Getchar()) != 'Q' && (c != ERR))
+ AddCh(c);
+ break;
+
+ case 'd':
+ slk_clear();
+ break;
+
+ case 'l':
+ fmt = 0;
+ break;
+
+ case 'c':
+ fmt = 1;
+ break;
+
+ case 'r':
+ fmt = 2;
+ break;
+
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
+ _nc_STRCPY(buf, "", sizeof(buf));
+ if ((s = slk_label(c - '0')) != 0) {
+ _nc_STRNCPY(buf, s, (size_t) 8);
+ }
+ wGetstring(stdscr, buf, 8);
+ slk_set((c - '0'), buf, fmt);
+ slk_refresh();
+ move(SLK_WORK, 0);
+ clrtobot();
+ break;
+
+ case case_QUIT:
+ goto done;
+
+#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
+ case KEY_RESIZE:
+ wnoutrefresh(stdscr);
+ break;
+#endif
+
+ default:
+ if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
+ 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(), TRUE));
+
+ done:
+ slk_clear();
+ erase();
+ endwin();
+}
+
+#if USE_WIDEC_SUPPORT
+#define SLKLEN 8
+static void
+wide_slk_test(void)
+/* exercise the soft keys */
+{
+ int c, fmt = 1;
+ wchar_t buf[SLKLEN + 1];
+ char *s;
+ chtype attr = A_NORMAL;
+ unsigned at_code = 0;
+ int fg = COLOR_BLACK;
+ int bg = COLOR_WHITE;
+ NCURSES_PAIRS_T pair = 0;
+ ATTR_TBL my_list[SIZEOF(attrs_to_test)];
+ unsigned my_size = init_attr_list(my_list, term_attrs());
+
+ c = CTRL('l');
+ if (use_colors) {
+ call_slk_color(fg, bg);
+ }
+ do {
+ move(0, 0);
+ switch (c) {
+ case CTRL('l'):
+ erase();
+ attr_on(WA_BOLD, NULL);
+ MvAddStr(0, 20, "Soft Key Exerciser");
+ attr_off(WA_BOLD, NULL);
+
+ slk_help();
+ /* fall through */
+
+ case 'a':
+ slk_restore();
+ break;
+
+ case 'e':
+ wclear(stdscr);
+ break;
+
+ case 's':
+ MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
+ while ((c = Getchar()) != 'Q' && (c != ERR))
+ AddCh(c);
+ break;
+
+ case 'd':
+ slk_clear();
+ break;
+
+ case 'l':
+ fmt = 0;
+ break;
+
+ case 'c':
+ fmt = 1;
+ break;
+
+ case 'r':
+ fmt = 2;
+ break;
+
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
+ *buf = 0;
+ if ((s = slk_label(c - '0')) != 0) {
+ char *temp = strdup(s);
+ size_t used = strlen(temp);
+ size_t want = SLKLEN;
+ size_t test;
+#ifndef state_unused
+ mbstate_t state;
+#endif
+
+ buf[0] = L'\0';
+ while (want > 0 && used != 0) {
+ const char *base = s;
+ reset_mbytes(state);
+ test = count_mbytes(base, 0, &state);
+ if (test == (size_t) -1) {
+ temp[--used] = 0;
+ } else if (test > want) {
+ temp[--used] = 0;
+ } else {
+ reset_mbytes(state);
+ trans_mbytes(buf, base, want, &state);
+ break;
+ }
+ }
+ free(temp);
+ }
+ wGet_wstring(stdscr, buf, SLKLEN);
+ slk_wset((c - '0'), buf, fmt);
+ slk_refresh();
+ move(SLK_WORK, 0);
+ clrtobot();
+ break;
+
+ case case_QUIT:
+ goto done;
+
+ case 'F':
+ if (use_colors) {
+ fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
+ call_slk_color(fg, bg);
+ }
+ break;
+ case 'B':
+ if (use_colors) {
+ bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
+ call_slk_color(fg, bg);
+ }
+ break;
+#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
+ case KEY_RESIZE:
+ wnoutrefresh(stdscr);
+ break;
+#endif
+ default:
+ if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
+ slk_attr_set(attr, (NCURSES_COLOR_T) (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(), TRUE));
+
+ done:
+ slk_clear();
+ erase();
+ endwin();
+}
+#endif
+#endif /* SLK_INIT */
+
+static void
+show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
+{
+ unsigned first = 0;
+ unsigned last = 255;
+ unsigned code;
+ int count;
+
+ erase();
+ attron(A_BOLD);
+ MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
+ first, last);
+ attroff(A_BOLD);
+ refresh();
+
+ for (code = first; code <= last; ++code) {
+ int row = (int) (2 + (code / 16));
+ int col = (int) (5 * (code % 16));
+ IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
+ for (count = 1; count < repeat; ++count) {
+ AddCh(colored_chtype(code, attr, pair));
+ }
+ }
+
+}
+
+/*
+ * Show a slice of 32 characters, allowing those to be repeated up to the
+ * screen's width.
+ *
+ * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
+ * terminal to perform functions. The remaining codes can be graphic.
+ */
+static void
+show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
+{
+ unsigned code;
+ unsigned first = (unsigned) base;
+ unsigned last = first + (unsigned) pagesize - 2;
+ bool C1 = (first == 128);
+ int reply;
+
+ erase();
+ attron(A_BOLD);
+ MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
+ C1 ? "C1" : "GR", first, last);
+ attroff(A_BOLD);
+ refresh();
+
+ for (code = first; code <= last; code++) {
+ int count = repeat;
+ int row = 2 + ((int) (code - first) % (pagesize / 2));
+ int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
+ char tmp[80];
+ _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
+ MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
+
+ do {
+ if (C1)
+ nodelay(stdscr, TRUE);
+ echochar(colored_chtype(code, attr, pair));
+ if (C1) {
+ /* (yes, this _is_ crude) */
+ while ((reply = Getchar()) != ERR) {
+ AddCh(UChar(reply));
+ napms(10);
+ }
+ nodelay(stdscr, FALSE);
+ }
+ } while (--count > 0);
+ }
+}
+
+#define PC_COLS 4
+
+static void
+show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
+{
+ unsigned code;
+
+ erase();
+ attron(A_BOLD);
+ MvPrintw(0, 20, "Display of PC Character Codes");
+ attroff(A_BOLD);
+ refresh();
+
+ for (code = 0; code < 16; ++code) {
+ MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
+ }
+ for (code = 0; code < 256; code++) {
+ int count = repeat;
+ int row = 3 + (int) (code / 16) + (code >= 128);
+ int col = 8 + (int) (code % 16) * PC_COLS;
+ if ((code % 16) == 0)
+ MvPrintw(row, 0, "0x%02x:", code);
+ move(row, col);
+ do {
+ switch (code) {
+ case '\n':
+ case '\r':
+ case '\b':
+ case '\f':
+ case '\033':
+ case 0x9b:
+ /*
+ * Skip the ones that do not work.
+ */
+ break;
+ default:
+ AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
+ break;
+ }
+ } while (--count > 0);
+ }
+}
+
+static void
+show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
+{
+ (void) repeat;
+
+ attr |= (attr_t) COLOR_PAIR(pair);
+
+ erase();
+ attron(A_BOLD);
+ MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
+ attroff(A_BOLD);
+ refresh();
+ /* *INDENT-OFF* */
+ wborder(stdscr,
+ colored_chtype(ACS_VLINE, attr, pair),
+ colored_chtype(ACS_VLINE, attr, pair),
+ colored_chtype(ACS_HLINE, attr, pair),
+ colored_chtype(ACS_HLINE, attr, pair),
+ colored_chtype(ACS_ULCORNER, attr, pair),
+ colored_chtype(ACS_URCORNER, attr, pair),
+ colored_chtype(ACS_LLCORNER, attr, pair),
+ colored_chtype(ACS_LRCORNER, attr, pair));
+ MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
+ MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
+ MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
+ MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
+ MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
+ MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
+ MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
+ /* *INDENT-ON* */
+
+}
+
+static int
+show_1_acs(int n, int repeat, const char *name, chtype code)
+{
+ const int height = 16;
+ int row = 2 + (n % height);
+ int col = (n / height) * COLS / 2;
+
+ MvPrintw(row, col, "%*s : ", COLS / 4, name);
+ do {
+ AddCh(code);
+ } while (--repeat > 0);
+ return n + 1;
+}
+
+static void
+show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
+/* display the ACS character set */
+{
+ int n;
+
+#define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
+
+ erase();
+ attron(A_BOLD);
+ MvAddStr(0, 20, "Display of the ACS Character Set");
+ attroff(A_BOLD);
+ refresh();
+
+ n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
+ n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
+ n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
+ n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
+ n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
+ n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
+ n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
+ n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
+
+ /*
+ * HPUX's ACS definitions are broken here. Just give up.
+ */
+#if !(defined(__hpux) && !defined(NCURSES_VERSION))
+ n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
+ n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
+ n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
+ n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
+ n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
+ n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
+ n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
+ n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
+ n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
+ n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
+ n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
+ n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
+ n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
+ n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
+
+ n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
+ n = show_1_acs(n, repeat, BOTH(ACS_PI));
+ n = show_1_acs(n, repeat, BOTH(ACS_S1));
+ n = show_1_acs(n, repeat, BOTH(ACS_S3));
+ n = show_1_acs(n, repeat, BOTH(ACS_S7));
+ (void) show_1_acs(n, repeat, BOTH(ACS_S9));
+#endif
+}
+
+static void
+acs_display(void)
+{
+ int c = 'a';
+ int pagesize = 32;
+ char *term = getenv("TERM");
+ const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
+ ? "p=PC, "
+ : "");
+ chtype attr = A_NORMAL;
+ int digit = 0;
+ int repeat = 1;
+ int fg = COLOR_BLACK;
+ int bg = COLOR_BLACK;
+ unsigned at_code = 0;
+ NCURSES_PAIRS_T pair = 0;
+ void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
+ ATTR_TBL my_list[SIZEOF(attrs_to_test)];
+ unsigned my_size = init_attr_list(my_list, termattrs());
+
+ do {
+ switch (c) {
+ case CTRL('L'):
+ Repaint();
+ break;
+ case 'a':
+ ToggleAcs(last_show_acs, show_acs_chars);
+ break;
+ case 'p':
+ if (*pch_kludge)
+ ToggleAcs(last_show_acs, show_pc_chars);
+ else
+ beep();
+ break;
+ case 'w':
+ if (pagesize == 32) {
+ pagesize = 256;
+ } else {
+ pagesize = 32;
+ }
+ break;
+ case 'x':
+ ToggleAcs(last_show_acs, show_box_chars);
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ digit = (c - '0');
+ last_show_acs = 0;
+ break;
+ case '-':
+ if (digit > 0) {
+ --digit;
+ last_show_acs = 0;
+ } else {
+ beep();
+ }
+ break;
+ case '+':
+ if (digit < 3) {
+ ++digit;
+ last_show_acs = 0;
+ } else {
+ beep();
+ }
+ break;
+ case '>':
+ if (repeat < (COLS / 4))
+ ++repeat;
+ break;
+ case '<':
+ if (repeat > 1)
+ --repeat;
+ break;
+ default:
+ if (cycle_attr(c, &at_code, &attr, my_list, my_size)
+ || cycle_colors(c, &fg, &bg, &pair)) {
+ break;
+ } else {
+ beep();
+ }
+ break;
+ }
+ if (pagesize != 32) {
+ show_256_chars(repeat, attr, pair);
+ } else if (last_show_acs != 0) {
+ last_show_acs(repeat, attr, pair);
+ } else {
+ show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
+ }
+
+ MvPrintw(LINES - 3, 0,
+ "Note: ANSI terminals may not display C1 characters.");
+ MvPrintw(LINES - 2, 0,
+ "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
+ pch_kludge);
+ if (use_colors) {
+ MvPrintw(LINES - 1, 0,
+ "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
+ my_list[at_code].name,
+ fg, bg);
+ } else {
+ MvPrintw(LINES - 1, 0,
+ "v/V cycles through video attributes (%s).",
+ my_list[at_code].name);
+ }
+ refresh();
+ } while (!isQuit(c = Getchar(), TRUE));
+
+ Pause();
+ erase();
+ endwin();
+}
+
+#if USE_WIDEC_SUPPORT
+static cchar_t *
+merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
+{
+ int count;
+
+ *dst = *src;
+ do {
+ TEST_CCHAR(src, count, {
+ attr |= (test_attrs & A_ALTCHARSET);
+ setcchar(dst, test_wch, attr, pair, NULL);
+ }
+ , {
+ ;
+ });
+ } while (0);
+ return dst;
+}
+
+/*
+ * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
+ * display. If there are no repeats, we could normally display 16 lines of 64
+ * characters (1024 total). However, taking repeats and double-width cells
+ * into account, use 256 characters for the page.
+ */
+static void
+show_paged_widechars(int base,
+ int pagesize,
+ int repeat,
+ int space,
+ attr_t attr,
+ NCURSES_PAIRS_T pair)
+{
+ int first = base * pagesize;
+ int last = first + pagesize - 1;
+ int per_line = 16;
+ cchar_t temp;
+ wchar_t code;
+ wchar_t codes[10];
+
+ erase();
+ attron(A_BOLD);
+ MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
+ attroff(A_BOLD);
+
+ for (code = (wchar_t) first; (int) code <= last; code++) {
+ int row = (2 + ((int) code - first) / per_line);
+ int col = 5 * ((int) code % per_line);
+ int count;
+
+ memset(&codes, 0, sizeof(codes));
+ codes[0] = code;
+ setcchar(&temp, codes, attr, pair, 0);
+ move(row, col);
+ if (wcwidth(code) == 0 && code != 0) {
+ AddCh((chtype) space |
+ (A_REVERSE ^ attr) |
+ (attr_t) COLOR_PAIR(pair));
+ }
+ add_wch(&temp);
+ for (count = 1; count < repeat; ++count) {
+ add_wch(&temp);
+ }
+ }
+}
+
+static void
+show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T 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 = (wchar_t) first; (int) 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;
+
+ _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
+ "%3ld (0x%lx)", (long) code, (long) code);
+ MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
+
+ memset(&codes, 0, sizeof(codes));
+ codes[0] = code;
+ 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((chtype) space |
+ (A_REVERSE ^ attr) |
+ (attr_t) COLOR_PAIR(pair));
+ }
+ /*
+ * This uses echo_wchar(), for comparison with the normal 'f'
+ * test (and to make a test-case for echo_wchar()). The screen
+ * may 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);
+ (void) y;
+ if (x >= col + (COLS / 2) - 2)
+ break;
+ } while (--count > 0);
+ }
+}
+
+static int
+show_1_wacs(int n, int repeat, 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);
+ while (--repeat >= 0) {
+ add_wch(code);
+ }
+ return n + 1;
+}
+
+#define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
+
+static void
+show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T 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, repeat, BOTH2(WACS_ULCORNER));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
+
+#ifdef CURSES_WACS_ARRAY
+ n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
+ (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
+#endif
+}
+
+#ifdef WACS_D_PLUS
+static void
+show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T 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, repeat, BOTH2(WACS_D_ULCORNER));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
+
+#ifdef CURSES_WACS_ARRAY
+ n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
+ (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
+#endif
+}
+#endif
+
+#ifdef WACS_T_PLUS
+static void
+show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T 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, repeat, BOTH2(WACS_T_ULCORNER));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
+
+#ifdef CURSES_WACS_ARRAY
+ n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
+
+ n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
+ n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
+ (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
+#endif
+}
+#endif
+
+#undef MERGE_ATTR
+
+#define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
+
+static void
+show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
+{
+ cchar_t temp[8];
+
+ (void) repeat;
+ erase();
+ attron(A_BOLD);
+ MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
+ attroff(A_BOLD);
+ refresh();
+
+ wborder_set(stdscr,
+ MERGE_ATTR(0, WACS_VLINE),
+ MERGE_ATTR(1, WACS_VLINE),
+ MERGE_ATTR(2, WACS_HLINE),
+ MERGE_ATTR(3, WACS_HLINE),
+ MERGE_ATTR(4, WACS_ULCORNER),
+ MERGE_ATTR(5, WACS_URCORNER),
+ MERGE_ATTR(6, WACS_LLCORNER),
+ MERGE_ATTR(7, WACS_LRCORNER));
+ /* *INDENT-OFF* */
+ (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
+ (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
+ (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
+ (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
+ (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
+ (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
+ (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
+ /* *INDENT-ON* */
+
+}
+
+#undef MERGE_ATTR
+
+static int
+show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T 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);
+ (void) attr_set(attr, pair, 0);
+ _nc_STRNCPY(temp, code, 20);
+ addstr(temp);
+ (void) 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(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
+{
+ int n;
+
+ (void) repeat;
+ 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");
+ (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
+ /* *INDENT-ON* */
+
+}
+
+/* display the wide-ACS character set */
+static void
+wide_acs_display(void)
+{
+ int c = 'a';
+ int digit = 0;
+ int repeat = 1;
+ int space = ' ';
+ int pagesize = 32;
+ chtype attr = A_NORMAL;
+ int fg = COLOR_BLACK;
+ int bg = COLOR_BLACK;
+ unsigned at_code = 0;
+ NCURSES_PAIRS_T pair = 0;
+ void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
+ ATTR_TBL my_list[SIZEOF(attrs_to_test)];
+ unsigned my_size = init_attr_list(my_list, term_attrs());
+
+ do {
+ switch (c) {
+ case CTRL('L'):
+ Repaint();
+ break;
+ case 'a':
+ ToggleAcs(last_show_wacs, show_wacs_chars);
+ break;
+#ifdef WACS_D_PLUS
+ case 'd':
+ ToggleAcs(last_show_wacs, show_wacs_chars_double);
+ break;
+#endif
+#ifdef WACS_T_PLUS
+ case 't':
+ ToggleAcs(last_show_wacs, show_wacs_chars_thick);
+ break;
+#endif
+ case 'w':
+ if (pagesize == 32) {
+ pagesize = 256;
+ } else {
+ pagesize = 32;
+ }
+ break;
+ case 'x':
+ ToggleAcs(last_show_wacs, show_wbox_chars);
+ break;
+ case 'u':
+ ToggleAcs(last_show_wacs, show_utf8_chars);
+ break;
+ default:
+ if (c < 256 && isdigit(c)) {
+ digit = (c - '0');
+ last_show_wacs = 0;
+ } else if (c == '+') {
+ ++digit;
+ last_show_wacs = 0;
+ } else if (c == '-' && digit > 0) {
+ --digit;
+ last_show_wacs = 0;
+ } else if (c == '>' && repeat < (COLS / 4)) {
+ ++repeat;
+ } else if (c == '<' && repeat > 1) {
+ --repeat;
+ } else if (c == '_') {
+ space = (space == ' ') ? '_' : ' ';
+ last_show_wacs = 0;
+ } else if (cycle_attr(c, &at_code, &attr, my_list, my_size)
+ || cycle_colors(c, &fg, &bg, &pair)) {
+ if (last_show_wacs != 0)
+ break;
+ } else {
+ beep();
+ break;
+ }
+ break;
+ }
+ if (pagesize != 32) {
+ show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
+ } else if (last_show_wacs != 0) {
+ last_show_wacs(repeat, attr, pair);
+ } else {
+ show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
+ }
+
+ MvPrintw(LINES - 4, 0,
+ "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
+ MvPrintw(LINES - 3, 2,
+ "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
+ if (use_colors) {
+ MvPrintw(LINES - 2, 2,
+ "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
+ my_list[at_code].name,
+ fg, bg);
+ } else {
+ MvPrintw(LINES - 2, 2,
+ "v/V cycles through video attributes (%s).",
+ my_list[at_code].name);
+ }
+ refresh();
+ } while (!isQuit(c = Getchar(), TRUE));