+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) {
+ sprintf(temp, "%02d", color);
+ width = 4;
+ } else if (color >= 8) {
+ sprintf(temp, "[%02d]", color);
+ } else if (color < 0) {
+ strcpy(temp, "default");
+ } else {
+ strcpy(temp, 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");
+ 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; }
+
+/* generate a color test pattern */
+static void
+color_test(void)
+{
+ short i;
+ int top = 0, width;
+ int base_row = 0;
+ int grid_top = top + 3;
+ int page_size = (LINES - grid_top);
+ int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
+ int row_limit;
+ int per_row;
+ char numbered[80];
+ 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;
+
+ if (COLORS * COLORS == COLOR_PAIRS) {
+ int limit = (COLORS - min_colors) * (COLORS - min_colors);
+ if (pairs_max > limit)
+ pairs_max = limit;
+ } else {
+ if (pairs_max > COLOR_PAIRS)
+ pairs_max = COLOR_PAIRS;
+ }
+
+ while (!done) {
+ int shown = 0;
+
+ /* this assumes an 80-column line */
+ if (opt_wide) {
+ width = 4;
+ hello = "Test";
+ per_row = (COLORS > 8) ? 16 : 8;
+ } else {
+ width = 8;
+ hello = "Hello";
+ per_row = 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%s\n",
+ pairs_max, COLORS,
+ min_colors ? " besides 'default'" : "");
+
+ clrtobot();
+ (void) 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 = (short) (base_row * per_row); i < pairs_max; i++) {
+ int row = grid_top + (i / per_row) - base_row;
+ int col = (i % per_row + 1) * width;
+ short pair = i;
+
+#define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
+#define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
+ if (row >= 0 && move(row, col) != ERR) {
+ short fg = InxToFG(i);
+ short bg = InxToBG(i);
+
+ 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);
+ if (opt_revs)
+ attron((attr_t) A_REVERSE);
+
+ if (opt_nums) {
+ sprintf(numbered, "{%02X}", 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 '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 '?':
+ 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();
+}
+
+#if USE_WIDEC_SUPPORT
+/* generate a color test pattern */
+static void
+wide_color_test(void)
+{
+ int c;
+ 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 row_limit;
+ int per_row;
+ char numbered[80];
+ 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[10];
+ WINDOW *helpwin;
+
+ if (COLORS * COLORS == COLOR_PAIRS) {
+ int limit = (COLORS - min_colors) * (COLORS - min_colors);
+ if (pairs_max > limit)
+ pairs_max = limit;
+ } else {
+ if (pairs_max > COLOR_PAIRS)
+ pairs_max = COLOR_PAIRS;
+ }
+
+ while (!done) {
+ int shown = 0;
+
+ /* this assumes an 80-column line */
+ if (opt_wide) {
+ width = 4;
+ hello = "Test";
+ per_row = (COLORS > 8) ? 16 : 8;
+ } else {
+ width = 8;
+ hello = "Hello";
+ per_row = 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%s\n",
+ pairs_max, COLORS,
+ min_colors ? " besides 'default'" : "");
+
+ clrtobot();
+ (void) 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;
+ short pair = (short) i;
+
+ if (row >= 0 && move(row, col) != ERR) {
+ init_pair(pair, InxToFG(i), InxToBG(i));
+ 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_revs)
+ attr_on((attr_t) A_REVERSE, NULL);
+
+ if (opt_nums) {
+ sprintf(numbered, "{%02X}", i);
+ if (opt_xchr) {
+ make_fullwidth_text(buffer, numbered);
+ } else {
+ make_narrow_text(buffer, numbered);
+ }
+ }
+ addnwstr(buffer, width);
+ 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 (c = 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 '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 '?':
+ 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();
+}
+#endif /* USE_WIDEC_SUPPORT */
+
+static void
+change_color(short current, int field, int value, int usebase)
+{
+ short red, green, blue;
+
+ color_content(current, &red, &green, &blue);
+
+ switch (field) {
+ case 0:
+ red = (short) (usebase ? (red + value) : value);
+ break;
+ case 1:
+ green = (short) (usebase ? (green + value) : value);
+ break;
+ case 2:
+ blue = (short) (usebase ? (blue + value) : value);
+ break;
+ }
+
+ if (init_color(current, red, green, blue) == ERR)
+ beep();
+}
+
+static void
+init_all_colors(void)
+{
+ short c;
+
+ for (c = 0; c < COLORS; ++c)
+ init_color(c,
+ all_colors[c].red,
+ all_colors[c].green,
+ all_colors[c].blue);
+}
+
+#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 = 0;
+ int this_c = 0, value = 0, field = 0;
+ int last_c;
+ int top_color = 0;
+ int page_size = (LINES - 6);
+
+ init_all_colors();
+ refresh();
+
+ for (i = 0; i < max_colors; i++)
+ init_pair((short) i, (short) COLOR_WHITE, (short) i);
+
+ mvprintw(LINES - 2, 0, "Number: %d", value);
+
+ do {
+ short red, green, blue;
+
+ attron(A_BOLD);
+ mvaddstr(0, 20, "Color RGB Value Editing");
+ attroff(A_BOLD);
+
+ for (i = (short) top_color;
+ (i - top_color < page_size)
+ && (i < max_colors); i++) {
+ char numeric[80];
+
+ sprintf(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(COLOR_PAIR(i));
+ addstr(" ");
+ (void) attrset(A_NORMAL);
+
+ color_content((short) i, &red, &green, &blue);
+ addstr(" R = ");
+ if (current == i && field == 0)
+ attron(A_STANDOUT);
+ printw("%04d", red);
+ if (current == i && field == 0)
+ (void) attrset(A_NORMAL);
+ addstr(", G = ");
+ if (current == i && field == 1)
+ attron(A_STANDOUT);
+ printw("%04d", green);
+ if (current == i && field == 1)
+ (void) attrset(A_NORMAL);
+ addstr(", B = ");
+ if (current == i && field == 2)
+ attron(A_STANDOUT);
+ printw("%04d", blue);
+ if (current == i && field == 2)
+ (void) attrset(A_NORMAL);
+ (void) attrset(A_NORMAL);
+ printw(" ( %3d %3d %3d )",
+ scaled_rgb(red),
+ scaled_rgb(green),
+ 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) {
+ 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 KEY_RIGHT:
+ field = (field == 2 ? 0 : field + 1);
+ break;
+
+ 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((short) current, field, value, 1);
+ break;
+
+ case '-':
+ change_color((short) current, field, -value, 1);
+ break;
+
+ case '=':
+ change_color((short) current, field, value, 0);
+ break;
+
+ case '?':
+ 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("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);
+ 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));
+
+ erase();
+
+ /*
+ * ncurses does not reset each color individually when calling endwin().
+ */
+ init_all_colors();
+
+ endwin();
+}
+
+/****************************************************************************
+ *
+ * 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();
+}
+
+/****************************************************************************
+ *
+ * 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)
+{
+ init_pair(1, bg, 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;
+ short pair = 0;
+#endif
+
+ 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((chtype) 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':
+ (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
+ strcpy(buf, "");
+ if ((s = slk_label(c - '0')) != 0) {
+ strncpy(buf, s, 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)) {
+ 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()));
+
+ 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;
+ short pair = 0;
+
+ 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((chtype) 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':
+ (void) 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 = (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;
+#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
+ case KEY_RESIZE:
+ wnoutrefresh(stdscr);
+ 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()));
+
+ done:
+ slk_clear();
+ erase();
+ endwin();