From: PatR Date: Tue, 1 Feb 2022 02:20:34 +0000 (-0800) Subject: topten's so (standout) handling X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=532cddbd35310bc97dcbe26dd54e4a72421caa41;p=nethack topten's so (standout) handling This fixes the broken code that was using a boolean as an integer. I didn't try to track down when it changed or what it looked like before the change. The intended effect is fairly straightforward; just padding a bold line with spaces. I've no idea why someone deciced that that was useful though. It also fixes something I broke six years ago: tty_exit_nhwindows() releases the termcap data needed for turning bold on and off, so raw_print_bold() used by topten() stopped working on tty then. Not fixed: the code in really_done() for dealing with topten() vs the 'toptenwin' option really ought to be redone. --- diff --git a/src/end.c b/src/end.c index 86fa99ae1..f842ae038 100644 --- a/src/end.c +++ b/src/end.c @@ -1649,11 +1649,24 @@ really_done(int how) destroy_nhwindow(endwin); dump_close_log(); - /* "So when I die, the first thing I will see in Heaven is a - * score list?" */ + /* + * "So when I die, the first thing I will see in Heaven is a score list?" + * + * topten() updates 'logfile' and 'xlogfile', when they're enabled. + * Then the current game's score is shown in its relative position + * within high scores, and 'record' is updated if that makes the cut. + * + * FIXME! + * If writing topten with raw_print(), which will usually be sent to + * stdout, we call exit_nhwindows() first in case it erases the screen. + * But when writing topten to a window, we call exit_nhwindows() + * after topten() because that needs the windowing system to still + * be up. This sequencing is absurd; we need something like + * raw_prompt("--More--") (or "Press to continue.") that + * topten() can call for !toptenwin before returning here. + */ if (have_windows && !iflags.toptenwin) exit_nhwindows((char *) 0), have_windows = FALSE; - /* update 'logfile' and 'xlogfile', if enabled, and maybe 'record' */ topten(how, endtime); if (have_windows) exit_nhwindows((char *) 0); diff --git a/src/topten.c b/src/topten.c index f8954ddbc..62ae49a4e 100644 --- a/src/topten.c +++ b/src/topten.c @@ -891,8 +891,16 @@ topten(int how, time_t when) free_ttlist(tt_head); showwin: - if (iflags.toptenwin && !done_stopprint) - display_nhwindow(g.toptenwin, TRUE); + if (!done_stopprint) { + if (iflags.toptenwin) { + display_nhwindow(g.toptenwin, TRUE); + } else { + /* when not a window, we need something comparable to more() + but can't use it directly because we aren't dealing with + the message window */ + ; + } + } destroywin: if (!t0_used) dealloc_ttentry(t0); @@ -1042,11 +1050,11 @@ outentry(int rank, struct toptenentry* t1, boolean so) Strcpy(linebuf3, bp); else Strcpy(linebuf3, bp + 1); - *bp = 0; + *bp = '\0'; if (so) { while (bp < linebuf + (COLNO - 1)) *bp++ = ' '; - *bp = 0; + *bp = '\0'; topten_print_bold(linebuf); } else topten_print(linebuf); @@ -1069,11 +1077,9 @@ outentry(int rank, struct toptenentry* t1, boolean so) if (so) { bp = eos(linebuf); - if (so >= COLNO) - so = COLNO - 1; - while (bp < linebuf + so) + while (bp < linebuf + (COLNO - 1)) *bp++ = ' '; - *bp = 0; + *bp = '\0'; topten_print_bold(linebuf); } else topten_print(linebuf); diff --git a/win/tty/termcap.c b/win/tty/termcap.c index 6ab407452..9be89d9c7 100644 --- a/win/tty/termcap.c +++ b/win/tty/termcap.c @@ -65,6 +65,9 @@ static char tgotobuf[20]; #endif #endif /* TERMLIB */ +/* these don't need to be part of 'struct instance_globals g' */ +static char tty_standout_on[16], tty_standout_off[16]; + void tty_startup(int *wid, int *hgt) { @@ -264,6 +267,8 @@ tty_startup(int *wid, int *hgt) MR = Tgetstr("mr"); /* reverse */ MB = Tgetstr("mb"); /* blink */ MD = Tgetstr("md"); /* boldface */ + if (!SO) + SO = MD; MH = Tgetstr("mh"); /* dim */ ME = Tgetstr("me"); /* turn off all attributes */ if (!ME) @@ -304,6 +309,13 @@ tty_startup(int *wid, int *hgt) error("TERMCAP entry too big...\n"); free((genericptr_t) tptr); #endif /* TERMLIB */ + /* keep static copies of these so that raw_print_bold() will work + after exit_nhwindows(); if the sequences are too long, then bold + won't work after that--it will be rendered as ordinary text */ + if (nh_HI && strlen(nh_HI) < sizeof tty_standout_on) + Strcpy(tty_standout_on, nh_HI); + if (nh_HE && strlen(nh_HE) < sizeof tty_standout_off) + Strcpy(tty_standout_off, nh_HE); } /* note: at present, this routine is not part of the formal window interface @@ -1366,13 +1378,21 @@ term_end_attr(int attr) void term_start_raw_bold(void) { - xputs(nh_HI); + if (!nh_HI) + nh_HI = tty_standout_on; + + if (*nh_HI) + xputs(nh_HI); } void term_end_raw_bold(void) { - xputs(nh_HE); + if (!nh_HE) + nh_HE = tty_standout_off; + + if (*nh_HE) + xputs(nh_HE); } #ifdef TEXTCOLOR