From 29cadc04521a30351a1b2f96b9ec78ab3fe29f5e Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 22 Dec 2021 11:33:35 -0800 Subject: [PATCH] curses: fix "---" separators in ^P output This one has me baffled, first how/when it happened and then why no one reported it. The line current_mesg->turn = g.moves; vanished from mesg_add_line() at some point. It is visible in diff context of commit 99ed00012e076be07846edceb85e3e5e53f2bb02 from March, 2019 but I can't find any commit since that time which removed it. [I've been using git log --no-min-parents --no-max-parents --patch win/curses/cursmesg.c and then searching within the pager. Maybe that's flaky, but if so, things wouldn't be any less strange.] The missing line resulted in mesg->turn being uninitialized, so when ^P compared consecutive messages to decide whether they were issued on the same turn, arbitrary junk made them all seem to be from different turns so "---" got inserted before every message. I suppose that if someone uses a malloc that zeroes the memory it hands out, mesg->turn field would always be 0 and ^P would behave as if all messages were from the same turn, so not show any "---" separators. Then players might not be aware that "---" between groups of messages was intended. [The messages ought to be grouped by move rather than by turn, but that's something the core would have to provide.] --- doc/fixes37.0 | 4 ++++ win/curses/cursmesg.c | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/fixes37.0 b/doc/fixes37.0 index 48e6948a6..596c74d60 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -950,6 +950,10 @@ curses: line input that doesn't take place on the bottom line of the message curses: menu headings didn't use default text color curses: #perminv changes disabled menu_headings attribute for persistent inventory window headings; reinstate that +curses: messages were tagged by turn in 3.6.x so that ^P can place a separator + between groups of messages; somehow the line of code that recorded + the turn vanished so ^P behaved as if every message came on its own + distinct turn, resulting in lots of "---" separators Qt: at Xp levels above 20 with 'showexp' On, the combined status field "Level:NN/nnnnnnnn" was too big and truncated by a char at each end Qt: searching a text window for something that wasn't found and then searching diff --git a/win/curses/cursmesg.c b/win/curses/cursmesg.c index 150436052..093c78a18 100644 --- a/win/curses/cursmesg.c +++ b/win/curses/cursmesg.c @@ -372,13 +372,14 @@ curses_prev_mesg(void) for (count = 0; count < num_messages; ++count) { mesg = get_msg_line(do_lifo, count); - if (turn != mesg->turn && count != 0) { - curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0, - A_NORMAL, "---", MENU_ITEMFLAGS_NONE); + if (mesg->turn != turn) { + if (count > 0) /* skip separator for first line */ + curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0, + A_NORMAL, "---", MENU_ITEMFLAGS_NONE); + turn = mesg->turn; } curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0, A_NORMAL, mesg->str, MENU_ITEMFLAGS_NONE); - turn = mesg->turn; } if (!count) curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0, @@ -787,6 +788,7 @@ mesg_add_line(const char *mline) current_mesg->str = dupstr(mline); } } + current_mesg->turn = g.moves; if (num_messages == 0) { /* very first message; set up head */