From fd8b2b58d194df8b8e20ffb7bc354a25a703d319 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 28 Jan 2024 10:05:35 +0200 Subject: [PATCH] petattr: Change accepted parameters, add support for tty --- doc/Guidebook.mn | 20 +++-------- doc/Guidebook.tex | 22 +++--------- doc/fixes3-7-0.txt | 2 ++ include/optlist.h | 4 +-- src/options.c | 63 ++++++++++++++++++-------------- win/curses/cursmain.c | 2 +- win/curses/cursmisc.c | 84 ------------------------------------------- win/tty/wintty.c | 11 ++++-- 8 files changed, 57 insertions(+), 151 deletions(-) diff --git a/doc/Guidebook.mn b/doc/Guidebook.mn index a0857023f..5998097dc 100644 --- a/doc/Guidebook.mn +++ b/doc/Guidebook.mn @@ -4039,7 +4039,7 @@ The behavior of this option depends on the type of windowing you use. In text windowing, text highlighting or inverse video is often used; with tiles, generally displays a heart symbol near pets. .lp "" -With the curses interface, the +With the tty or curses interface, the .op petattr option controls how to highlight pets and setting it will turn the .op hilite_pet @@ -4383,21 +4383,9 @@ pets on the map. Effectively a superset of the .op hilite_pet boolean option. -Curses interface only; value is one or more of the following letters. -.sd -.si -.CC n "Normal text (no highlighting)" -.CC i "Inverse video (default)" -.CC b "Bold text" -.CC u "Underlined text" -.CC k "blinKing text" -.CC d "Dim text" -.CC t "iTalic text" -.CC l "Left line indicator" -.CC r "Right line indicator" -.ei -.ed -Some of those choices might not work, particularly the final three, +Curses or tty interface only; value is one of +none, bold, dim, underline, blink, and inverse. +Some of those choices might not work, depending upon terminal hardware or terminal emulation software. .lp "" Currently multiple highlight-style letters can be combined by simply diff --git a/doc/Guidebook.tex b/doc/Guidebook.tex index 9489bcb00..a8eb639d4 100644 --- a/doc/Guidebook.tex +++ b/doc/Guidebook.tex @@ -4410,7 +4410,7 @@ In text windowing, text highlighting or inverse video is often used; with tiles, generally displays a heart symbol near pets. %.lp "" -With the curses interface, the {\it petattr\/} +With the tty or curses interface, the {\it petattr\/} option controls how to highlight pets and setting it will turn the {\it hilite\verb+_+pet\/} option on or off as warranted. %.lp @@ -4801,23 +4801,9 @@ included for {\it all\/} despite that mode normally omitting gold. Specifies one or more text highlighting attributes to use when showing pets on the map. Effectively a superset of the {\it hilite\verb+_+pet\/} boolean option. -Curses interface only; value is one or more of the following letters. - -%.sd -%.si -{\tt n} --- Normal text (no highlighting)\\ -{\tt i} --- Inverse video (default)\\ -{\tt b} --- Bold text\\ -{\tt u} --- Underlined text\\ -{\tt k} --- blinKing text\\ -{\tt d} --- Dim text\\ -{\tt t} --- iTalic text\\ -{\tt l} --- Left line indicator\\ -{\tt r} --- Right line indicator\\ -%.ei -%.ed - -Some of those choices might not work, particularly the final three, +Curses or tty interface only; value is one of +none, bold, dim, underline, blink, and inverse. +Some of those choices might not work, depending upon terminal hardware or terminal emulation software. %.lp "" diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 2880203ad..9007fa369 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -2000,6 +2000,7 @@ curses: if user's terminal was set to 'application keypad mode' (DEC VTxxx nomenclature; set via 2 char "ESC =") and the terminfo or termcap entry told the terminal to send 8-bit escape sequences (via 3 char "ESC SPC G"), nethack wasn't recognizing number pad keys +curses: change petattr attributes, dropping support for curses-only ones macOS: Xcode project was failing to build if the path to the NetHack source tree contained a space; the issue was within some shell script code contained within the project @@ -2139,6 +2140,7 @@ tty: have dismiss pick-none menus instead of acting like '>' (not only wouldn't dismiss when not on last page, wouldn't dismiss at all) tty: menu search via ':' would clobber part of the menu with a status line refresh if the menu was tall enough to cover that +tty: add support for petattr Unix: when user name is used as default character name, keep hyphenated value intact instead stripping off dash and whatever follows as if that specified role/race/&c (worked once upon a time; broken since 3.3.0) diff --git a/include/optlist.h b/include/optlist.h index 3ffc2c064..bc3cf1ec3 100644 --- a/include/optlist.h +++ b/include/optlist.h @@ -529,8 +529,8 @@ static int optfn_##a(int, int, boolean, char *, char *); NHOPTC(perminv_mode, Advanced, 20, opt_in, set_in_game, Yes, Yes, No, Yes, NoAlias, "what to show in persistent inventory window") - NHOPTC(petattr, Advanced, 88, opt_in, set_in_game, /* curses only */ - No, Yes, No, No, NoAlias, "attributes for highlighting pets") + NHOPTC(petattr, Advanced, 88, opt_in, set_in_game, /* tty/curses only */ + No, Yes, No, Yes, NoAlias, "attributes for highlighting pets") /* pettype is ignored for some roles */ NHOPTC(pettype, Advanced, 4, opt_in, set_gameview, Yes, Yes, No, No, "pet", "your preferred initial pet type") diff --git a/src/options.c b/src/options.c index 53a0ecf3b..f9513f668 100644 --- a/src/options.c +++ b/src/options.c @@ -376,6 +376,7 @@ static int handler_perminv_mode(void); static int handler_pickup_burden(void); static int handler_pickup_types(void); static int handler_runmode(void); +static int handler_petattr(void); static int handler_sortloot(void); static int handler_symset(int); static int handler_whatis_coord(void); @@ -395,10 +396,6 @@ static void wc_set_font_name(int, char *); static int wc_set_window_colors(char *); static boolean illegal_menu_cmd_key(uchar); static const char *term_for_boolean(int, boolean *); -#ifdef CURSES_GRAPHICS -extern int curses_read_attrs(const char *attrs); -extern char *curses_fmt_attrs(char *); -#endif /* ask user if they want a tutorial, except if tutorial boolean option has been set in config - either on or off - in which case just obey that @@ -2950,8 +2947,8 @@ optfn_petattr( bad_negation(allopt[optidx].name, TRUE); retval = optn_err; } else if (op != empty_optstr) { -#ifdef CURSES_GRAPHICS - int itmp = curses_read_attrs(op); +#if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS) + int itmp = match_str2attr(op, FALSE); if (itmp == -1) { config_error_add("Unknown %s parameter '%s'", @@ -2960,9 +2957,6 @@ optfn_petattr( } else iflags.wc2_petattr = itmp; #else - /* non-curses windowports will not use this flag anyway - * but the above will not compile if we don't have curses. - * Just set it to a sensible default: */ iflags.wc2_petattr = ATR_INVERSE; #endif } else if (negated) { @@ -2976,11 +2970,9 @@ optfn_petattr( return retval; } if (req == get_val || req == get_cnf_val) { -#ifdef CURSES_GRAPHICS - if (WINDOWPORT(curses)) { - char tmpbuf[QBUFSZ]; - - Strcpy(opts, curses_fmt_attrs(tmpbuf)); +#if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS) + if (WINDOWPORT(tty) || WINDOWPORT(curses)) { + Strcpy(opts, attr2attrname(iflags.wc2_petattr)); } else #endif if (iflags.wc2_petattr != 0) @@ -2990,6 +2982,9 @@ optfn_petattr( else Strcpy(opts, defopt); } + if (req == do_handler) { + return handler_petattr(); + } return optn_ok; } @@ -4987,6 +4982,19 @@ optfn_boolean( case opt_tiled_map: iflags.wc_ascii_map = negated; break; + case opt_hilite_pet: +#if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS) + if (WINDOWPORT(tty) || WINDOWPORT(curses)) { + /* if we're enabling hilite_pet and petattr isn't set, + set it to Inverse; if we're disabling, leave petattr + alone so that re-enabling will get current value back + */ + if (iflags.hilite_pet && !iflags.wc2_petattr) + iflags.wc2_petattr = ATR_INVERSE; + } +#endif + go.opt_need_redraw = TRUE; + break; default: break; } @@ -5038,19 +5046,6 @@ optfn_boolean( go.opt_need_redraw = TRUE; go.opt_need_glyph_reset = TRUE; break; - case opt_hilite_pet: -#ifdef CURSES_GRAPHICS - if (WINDOWPORT(curses)) { - /* if we're enabling hilite_pet and petattr isn't set, - set it to Inverse; if we're disabling, leave petattr - alone so that re-enabling will get current value back - */ - if (iflags.hilite_pet && !iflags.wc2_petattr) - iflags.wc2_petattr = curses_read_attrs("I"); - } -#endif - go.opt_need_redraw = TRUE; - break; case opt_hitpointbar: if (VIA_WINDOWPORT()) { /* [is reassessment really needed here?] */ @@ -5752,6 +5747,20 @@ handler_runmode(void) return optn_ok; } +static int +handler_petattr(void) +{ + int tmp = query_attr("Select pet highlight attribute", iflags.wc2_petattr); + + if (tmp != -1) { + iflags.wc2_petattr = tmp; + iflags.hilite_pet = (iflags.wc2_petattr != ATR_NONE); + if (!go.opt_initial) + go.opt_need_redraw = TRUE; + } + return optn_ok; +} + static int handler_sortloot(void) { diff --git a/win/curses/cursmain.c b/win/curses/cursmain.c index 2d4f278bc..16f4d4ba4 100644 --- a/win/curses/cursmain.c +++ b/win/curses/cursmain.c @@ -909,7 +909,7 @@ curses_print_glyph( ch = glyphinfo->ttychar; color = glyphinfo->gm.sym.color; if ((special & MG_PET) && iflags.hilite_pet) { - attr = iflags.wc2_petattr; + attr = curses_convert_attr(iflags.wc2_petattr); } if ((special & MG_DETECT) && iflags.use_inverse) { attr = A_REVERSE; diff --git a/win/curses/cursmisc.c b/win/curses/cursmisc.c index 85e372373..9d722be35 100644 --- a/win/curses/cursmisc.c +++ b/win/curses/cursmisc.c @@ -768,92 +768,8 @@ curses_convert_attr(int attr) return curses_attr; } - -/* Map letter attributes from a string to bitmask. Return mask on - success (might be 0), or -1 if not found. */ - -int -curses_read_attrs(const char *attrs) -{ - int retattr = 0; - - if (!attrs || !*attrs) - return A_NORMAL; - - if (strchr(attrs, 'b') || strchr(attrs, 'B')) - retattr |= A_BOLD; - if (strchr(attrs, 'i') || strchr(attrs, 'I')) /* inverse */ - retattr |= A_REVERSE; - if (strchr(attrs, 'u') || strchr(attrs, 'U')) - retattr |= A_UNDERLINE; - if (strchr(attrs, 'k') || strchr(attrs, 'K')) - retattr |= A_BLINK; - if (strchr(attrs, 'd') || strchr(attrs, 'D')) - retattr |= A_DIM; -#ifdef A_ITALIC - if (strchr(attrs, 't') || strchr(attrs, 'T')) - retattr |= A_ITALIC; -#endif -#ifdef A_LEFTLINE - if (strchr(attrs, 'l') || strchr(attrs, 'L')) - retattr |= A_LEFTLINE; -#endif -#ifdef A_RIGHTLINE - if (strchr(attrs, 'r') || strchr(attrs, 'R')) - retattr |= A_RIGHTLINE; -#endif - if (retattr == 0) { - /* still default; check for none/normal */ - if (strchr(attrs, 'n') || strchr(attrs, 'N')) - retattr = A_NORMAL; - else - retattr = -1; /* error */ - } - return retattr; -} - -/* format iflags.wc2_petattr into "+a+b..." for set bits a, b, ... - (used by core's 'O' command; return value points past leading '+') */ -char * -curses_fmt_attrs(char *outbuf) -{ - int attr = iflags.wc2_petattr; - - outbuf[0] = '\0'; - if (attr == A_NORMAL) { - Strcpy(outbuf, "+N(None)"); - } else { - if (attr & A_BOLD) - Strcat(outbuf, "+B(Bold)"); - if (attr & A_REVERSE) - Strcat(outbuf, "+I(Inverse)"); - if (attr & A_UNDERLINE) - Strcat(outbuf, "+U(Underline)"); - if (attr & A_BLINK) - Strcat(outbuf, "+K(blinK)"); - if (attr & A_DIM) - Strcat(outbuf, "+D(Dim)"); -#ifdef A_ITALIC - if (attr & A_ITALIC) - Strcat(outbuf, "+T(iTalic)"); -#endif -#ifdef A_LEFTLINE - if (attr & A_LEFTLINE) - Strcat(outbuf, "+L(Left line)"); -#endif -#ifdef A_RIGHTLINE - if (attr & A_RIGHTLINE) - Strcat(outbuf, "+R(Right line)"); -#endif - } - if (!*outbuf) - Sprintf(outbuf, "+unknown [%d]", attr); - return &outbuf[1]; -} - /* Convert special keys into values that NetHack can understand. Currently this is limited to arrow keys, but this may be expanded. */ - int curses_convert_keys(int key) { diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 7b460cb08..259627f17 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -120,7 +120,7 @@ struct window_procs tty_procs = { | WC2_RESET_STATUS #endif | WC2_DARKGRAY | WC2_SUPPRESS_HIST | WC2_URGENT_MESG | WC2_STATUSLINES - | WC2_U_UTF8STR + | WC2_U_UTF8STR | WC2_PETATTR #if !defined(NO_TERMS) || defined(WIN32CON) | WC2_U_24BITCOLOR #endif @@ -3786,6 +3786,7 @@ tty_print_glyph( const glyph_info *bkglyphinfo) { boolean inverse_on = FALSE, colordone = FALSE, glyphdone = FALSE; + boolean petattr = FALSE; int ch, color; unsigned special; #ifdef ENHANCED_SYMBOLS @@ -3850,8 +3851,10 @@ tty_print_glyph( && bkglyphinfo && bkglyphinfo->framecolor != NO_COLOR) { ttyDisplay->framecolor = bkglyphinfo->framecolor; term_start_bgcolor(bkglyphinfo->framecolor); - } else if ((((special & MG_PET) != 0 && iflags.hilite_pet) - || ((special & MG_OBJPILE) != 0 && iflags.hilite_pile) + } else if ((special & MG_PET) != 0 && iflags.hilite_pet) { + term_start_attr(iflags.wc2_petattr); + petattr = TRUE; + } else if ((((special & MG_OBJPILE) != 0 && iflags.hilite_pile) || ((special & MG_FEMALE) != 0 && wizard && iflags.wizmgender) || ((special & (MG_DETECT | MG_BW_LAVA | MG_BW_ICE | MG_BW_SINK | MG_BW_ENGR)) != 0)) @@ -3880,6 +3883,8 @@ tty_print_glyph( if (inverse_on) term_end_attr(ATR_INVERSE); + else if (petattr) + term_end_attr(iflags.wc2_petattr); if (iflags.use_color) { /* turn off color as well, turning off ATR_INVERSE may have done this already and if so, we won't know the current state unless