From 98b5f581bb5157b80471c7208ad92baabf9788eb Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 21 Mar 2016 18:26:48 -0700 Subject: [PATCH] tty menu coloring There was a report during beta testing that menu lines which were displayed in color showed the whole line in color, unless/until an item was selected or unselected, in which case the '-', '+', or '#' was rendered in monochrome. The suggestion then was to redraw the selection character in color, but I went the other way. Menu entries will render the selector letter and selection indicator in monochrome all the time, and only the text of the menu entry will honor menucolors. --- doc/fixes36.1 | 1 + win/tty/wintty.c | 105 ++++++++++++++++++++++++++++++----------------- 2 files changed, 68 insertions(+), 38 deletions(-) diff --git a/doc/fixes36.1 b/doc/fixes36.1 index ee41c08b2..1d1b68691 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -205,6 +205,7 @@ tty: responding with or during role, race, &c selection behaved same as to quit; now it will pick [random] instead tty: rename struct variable 'filter' (role.c) and function 'winch()' (wintty.c) to avoid conflicts with +tty: skip selector letter and selection indicator (-,+,#) during menu coloring unix/X11: in top level Makefile, some commented out definitions of VARDATND misspelled pilemark.xbm (as pilemark.xpm) unix: options file with CR+LF line ends and an invalid option line resulted in diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 199474869..fd23b6336 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -152,14 +152,15 @@ STATIC_DCL void FDECL(erase_menu_or_text, STATIC_DCL void FDECL(free_window_info, (struct WinDesc *, BOOLEAN_P)); STATIC_DCL void FDECL(dmore, (struct WinDesc *, const char *)); STATIC_DCL void FDECL(set_item_state, (winid, int, tty_menu_item *)); -STATIC_DCL void FDECL(set_all_on_page, - (winid, tty_menu_item *, tty_menu_item *)); -STATIC_DCL void FDECL(unset_all_on_page, - (winid, tty_menu_item *, tty_menu_item *)); -STATIC_DCL void FDECL(invert_all_on_page, - (winid, tty_menu_item *, tty_menu_item *, CHAR_P)); -STATIC_DCL void FDECL(invert_all, - (winid, tty_menu_item *, tty_menu_item *, CHAR_P)); +STATIC_DCL void FDECL(set_all_on_page, (winid, tty_menu_item *, + tty_menu_item *)); +STATIC_DCL void FDECL(unset_all_on_page, (winid, tty_menu_item *, + tty_menu_item *)); +STATIC_DCL void FDECL(invert_all_on_page, (winid, tty_menu_item *, + tty_menu_item *, CHAR_P)); +STATIC_DCL void FDECL(invert_all, (winid, tty_menu_item *, + tty_menu_item *, CHAR_P)); +STATIC_DCL void FDECL(toggle_menu_attr, (BOOLEAN_P, int, int)); STATIC_DCL void FDECL(process_menu_window, (winid, struct WinDesc *)); STATIC_DCL void FDECL(process_text_window, (winid, struct WinDesc *)); STATIC_DCL tty_menu_item *FDECL(reverse, (tty_menu_item *)); @@ -1697,6 +1698,31 @@ char acc; /* group accelerator, 0 => all */ } } +/* support menucolor in addition to caller-supplied attribute */ +STATIC_OVL void +toggle_menu_attr(on, color, attr) +boolean on; +int color, attr; +{ + if (on) { + term_start_attr(attr); +#ifdef TEXTCOLOR + if (color != NO_COLOR) + term_start_color(color); +#endif + } else { +#ifdef TEXTCOLOR + if (color != NO_COLOR) + term_end_color(); +#endif + term_end_attr(attr); + } + +#ifndef TEXTCOLOR + nhUse(color); +#endif +} + STATIC_OVL void process_menu_window(window, cw) winid window; @@ -1704,7 +1730,7 @@ struct WinDesc *cw; { tty_menu_item *page_start, *page_end, *curr; long count; - int n, curr_page, page_lines, resp_len; + int n, attr_n, curr_page, page_lines, resp_len; boolean finished, counting, reset_count; char *cp, *rp, resp[QBUFSZ], gacc[QBUFSZ], *msave, *morestr, really_morc; #define MENU_EXPLICIT_CHOICE 0x7f /* pseudo menu manipulation char */ @@ -1775,8 +1801,8 @@ struct WinDesc *cw; page_end = cw->plist[curr_page + 1]; for (page_lines = 0, curr = page_start; curr != page_end; page_lines++, curr = curr->next) { - int color = NO_COLOR, attr = ATR_NONE; - boolean menucolr = FALSE; + int attr, color = NO_COLOR; + if (curr->selector) *rp++ = curr->selector; @@ -1786,6 +1812,21 @@ struct WinDesc *cw; (void) putchar(' '); ++ttyDisplay->curx; + + if (!iflags.use_menu_color + || !get_menu_coloring(curr->str, &color, &attr)) + attr = curr->attr; + + /* which character to start attribute highlighting; + whole line for headers and such, after the selector + character and space and selection indicator for menu + lines (including fake ones that simulate grayed-out + entries, so we don't rely on curr->identifier here) */ + attr_n = 0; /* whole line */ + if (curr->str[0] && curr->str[1] && curr->str[2] + && curr->str[1] == ' ' && index("-+#", curr->str[2])) + attr_n = 2 + 1; /* after selection indicator */ + /* * Don't use xputs() because (1) under unix it calls * tputstr() which will interpret a '*' as some kind @@ -1793,27 +1834,20 @@ struct WinDesc *cw; * actually output the character. We're faster doing * this. */ - if (iflags.use_menu_color - && (menucolr = get_menu_coloring(curr->str, &color, - &attr))) { - term_start_attr(attr); -#ifdef TEXTCOLOR - if (color != NO_COLOR) - term_start_color(color); -#endif - } else - term_start_attr(curr->attr); for (n = 0, cp = curr->str; + *cp && #ifndef WIN32CON - *cp - && (int) ++ttyDisplay->curx < (int) ttyDisplay->cols; - cp++, n++) + (int) ++ttyDisplay->curx < (int) ttyDisplay->cols; #else - *cp - && (int) ttyDisplay->curx < (int) ttyDisplay->cols; - cp++, n++, ttyDisplay->curx++) -#endif - if (n == 2 && curr->identifier.a_void != 0 + (int) ttyDisplay->curx < (int) ttyDisplay->cols; + ttyDisplay->curx++, +#endif + cp++, n++) { + if (n == attr_n && (color != NO_COLOR + || attr != ATR_NONE)) + toggle_menu_attr(TRUE, color, attr); + if (n == 2 + && curr->identifier.a_void != 0 && curr->selected) { if (curr->count == -1L) (void) putchar('+'); /* all selected */ @@ -1821,15 +1855,10 @@ struct WinDesc *cw; (void) putchar('#'); /* count selected */ } else (void) putchar(*cp); - if (iflags.use_menu_color && menucolr) { -#ifdef TEXTCOLOR - if (color != NO_COLOR) - term_end_color(); -#endif - term_end_attr(attr); - } else - term_end_attr(curr->attr); - } + } /* for *cp */ + if (n > attr_n && (color != NO_COLOR || attr != ATR_NONE)) + toggle_menu_attr(FALSE, color, attr); + } /* if npages > 0 */ } else { page_start = 0; page_end = 0; -- 2.50.1