From: PatR Date: Thu, 30 Mar 2017 21:14:38 +0000 (-0700) Subject: maybe fix #H5264 - screen clears on prompting X-Git-Tag: NetHack-3.6.1_RC01~507 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ba906b23443f4c8043fff52cb5e5f9151335a26;p=nethack maybe fix #H5264 - screen clears on prompting I couldn't reproduce the reported problem of the "In what direction?" being issued after the screen was cleared, but bypassing pline() in favor of putstr(WIN_MESSAGE) for tty prompts did also bypass if (vision_full_recalc) vision_recalc(0); if (u.ux) flush_screen(1); done in pline(). Inadvertent loss of the latter could conceivably be responsible for the problem. If so, the escape code used by cl_end() may be broken for somebody's termcap or terminfo setup since clearing to the end of the line in the message window shouldn't erase the rest of the screen. Regardless, the prompting change also bypassed the ability to show the prompt with raw_printf() if the display wasn't fully intialized yet, so some change to the revised prompting was necessary anyway. Switching back from putstr(WIN_MESSAGE) to pline() resulted in duplicated entries in DUMPLOG message history, one with bare prompt followed by another with response appended, so more tweaking was needed. The result is use of new custompline() instead of normal pline(). custompline() accepts some message handling flags to give more control over pline()'s behavior. It's a more general variation of Norep() but its caller needs to specify an extra argument. --- diff --git a/doc/fixes36.1 b/doc/fixes36.1 index 63c80b848..7fa058915 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -402,6 +402,7 @@ DUMPLOG: RIP tombstone was printed for characters who survived (ascended, escaped dungeon, quit, trickery or panic) artifact creation violated illiterate conduct when artifact name was assigned, behavior intended only for creating Sting or Orcrist via naming +tty: revert to pline() for issuing prompts (override MSGTYPE=hide differently) Platform- and/or Interface-Specific Fixes diff --git a/include/extern.h b/include/extern.h index fb3b7dfa4..82765df78 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 extern.h $NHDT-Date: 1489192904 2017/03/11 00:41:44 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.583 $ */ +/* NetHack 3.6 extern.h $NHDT-Date: 1490908458 2017/03/30 21:14:18 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.585 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1806,6 +1806,7 @@ E void FDECL(dumplogmsg, (const char *)); E void NDECL(dumplogfreemessages); #endif E void VDECL(pline, (const char *, ...)) PRINTF_F(1, 2); +E void VDECL(custompline, (unsigned, const char *, ...)) PRINTF_F(2, 3); E void VDECL(Norep, (const char *, ...)) PRINTF_F(1, 2); E void NDECL(free_youbuf); E void VDECL(You, (const char *, ...)) PRINTF_F(1, 2); diff --git a/include/hack.h b/include/hack.h index bf2273b2b..b7cf512c7 100644 --- a/include/hack.h +++ b/include/hack.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 hack.h $NHDT-Date: 1451683048 2016/01/01 21:17:28 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.68 $ */ +/* NetHack 3.6 hack.h $NHDT-Date: 1490908464 2017/03/30 21:14:24 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.76 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -359,6 +359,12 @@ enum explosion_types { #define XKILL_NOCORPSE 2 #define XKILL_NOCONDUCT 4 +/* pline_flags; mask values for custompline()'s first argument */ +/* #define PLINE_ORDINARY 0 */ +#define PLINE_NOREPEAT 1 +#define OVERRIDE_MSGTYPE 2 +#define SUPPRESS_HISTORY 4 + /* Macros for messages referring to hands, eyes, feet, etc... */ enum bodypart_types { ARM = 0, diff --git a/src/pline.c b/src/pline.c index 2a473625b..118ed82ee 100644 --- a/src/pline.c +++ b/src/pline.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pline.c $NHDT-Date: 1489192905 2017/03/11 00:41:45 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.57 $ */ +/* NetHack 3.6 pline.c $NHDT-Date: 1490908465 2017/03/30 21:14:25 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.58 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -6,7 +6,7 @@ */ #include "hack.h" -static boolean no_repeat = FALSE; +static unsigned pline_flags = 0; static char prevmsg[BUFSZ]; static char *FDECL(You_buf, (int)); @@ -98,7 +98,8 @@ VA_DECL(const char *, line) { /* start of vpline() or of nested block in USE_OLDARG's pline() */ char pbuf[3 * BUFSZ]; int ln; - xchar msgtyp; + int msgtyp; + boolean no_repeat; /* Do NOT use VA_START and VA_END in here... see above */ if (!line || !*line) @@ -134,18 +135,23 @@ VA_DECL(const char *, line) return; } + msgtyp = MSGTYP_NORMAL; + no_repeat = (pline_flags & PLINE_NOREPEAT) ? TRUE : FALSE; #ifdef DUMPLOG /* We hook here early to have options-agnostic output. * Unfortunately, that means Norep() isn't honored (general issue) and * that short lines aren't combined into one longer one (tty behavior). */ - dumplogmsg(line); + if ((pline_flags & SUPPRESS_HISTORY) == 0) + dumplogmsg(line); #endif + if ((pline_flags & OVERRIDE_MSGTYPE) != 0) { + msgtyp = msgtype_type(line, no_repeat); + if (msgtyp == MSGTYP_NOSHOW + || (msgtyp == MSGTYP_NOREP && !strcmp(line, prevmsg))) + return; + } - msgtyp = msgtype_type(line, no_repeat); - if (msgtyp == MSGTYP_NOSHOW - || (msgtyp == MSGTYP_NOREP && !strcmp(line, prevmsg))) - return; if (vision_full_recalc) vision_recalc(0); if (u.ux) @@ -170,15 +176,31 @@ VA_DECL(const char *, line) #endif } +/* pline() variant which can override MSGTYPE handling or suppress + message history (tty interface uses pline() to issue prompts and + they shouldn't be blockable via MSGTYPE=hide) */ +/*VARARGS2*/ +void custompline +VA_DECL2(unsigned, pflags, const char *, line) +{ + VA_START(line); + VA_INIT(line, const char *); + pline_flags = pflags; + vpline(line, VA_ARGS); + pline_flags = 0; + VA_END(); + return; +} + /*VARARGS1*/ void Norep VA_DECL(const char *, line) { VA_START(line); VA_INIT(line, const char *); - no_repeat = TRUE; + pline_flags = PLINE_NOREPEAT; vpline(line, VA_ARGS); - no_repeat = FALSE; + pline_flags = 0; VA_END(); return; } diff --git a/win/tty/getline.c b/win/tty/getline.c index 8d61aabfe..f3dd6cbf2 100644 --- a/win/tty/getline.c +++ b/win/tty/getline.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 getline.c $NHDT-Date: 1432512813 2015/05/25 00:13:33 $ $NHDT-Branch: master $:$NHDT-Revision: 1.28 $ */ +/* NetHack 3.6 getline.c $NHDT-Date: 1490908467 2017/03/30 21:14:27 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.31 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -50,20 +50,13 @@ getlin_hook_proc hook; register int c; struct WinDesc *cw = wins[WIN_MESSAGE]; boolean doprev = 0; - char tmpbuf[BUFSZ]; /* [QBUFSZ+1] should suffice */ if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more(); cw->flags &= ~WIN_STOP; ttyDisplay->toplin = 3; /* special prompt state */ ttyDisplay->inread++; - /* - * This used to use pline("%s ", query), but that made getline - * prompts be susceptible to suppression via the MSGTYPE mechanism. - * Having 'MSGTYPE=hide "# "' was particularly confusing. - */ - Sprintf(tmpbuf, "%s ", query); - tty_putstr(WIN_MESSAGE, 0, tmpbuf); + custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s ", query); *obufp = 0; for (;;) { (void) fflush(stdout); diff --git a/win/tty/topl.c b/win/tty/topl.c index cefc08f95..c4a778eef 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 topl.c $NHDT-Date: 1463787697 2016/05/20 23:41:37 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.33 $ */ +/* NetHack 3.6 topl.c $NHDT-Date: 1490908468 2017/03/30 21:14:28 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.36 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -385,14 +385,12 @@ char def; /* not pline("%s ", prompt); trailing space is wanted here in case of reprompt */ Strcat(prompt, " "); - /* pline("%s", prompt); -- see comment in hooked_tty_getlin() */ - tty_putstr(WIN_MESSAGE, 0, prompt); + custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s", prompt); } else { /* no restriction on allowed response, so always preserve case */ /* preserve_case = TRUE; -- moot since we're jumping to the end */ - /* pline("%s ", query); -- see above about tty_getlin() */ Sprintf(prompt, "%s ", query); - tty_putstr(WIN_MESSAGE, 0, prompt); + custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s", prompt); q = readchar(); goto clean_up; }