From 319dcf4746a81ef0ca413491bdf30b4c08f931c2 Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 9 Jun 2019 07:07:34 -0700 Subject: [PATCH] curses EDIT_GETLIN - discarding preloaded answer EDIT_GETLIN is more complicated on curses than on tty due to way that long lines are handled.... Using ESC to get rid of the default response removed it from the answer buffer but didn't erase back to the end of actual prompt, making it look as if it was still there. Fixing that for a one-line prompt+answer was needed and would have been easy but it also needs to be prepared to go back to prior lines. Both the prompt and the answer could conceivably span lines although in practice it will usually just be one line or else prompt+answer combined spanning to a second line. This hasn't been exhaustively tested been seems to be working correctly. --- doc/fixes36.3 | 4 +++- win/curses/cursmesg.c | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 304f16b59..e15c6b746 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.48 $ $NHDT-Date: 1560085861 2019/06/09 13:11:01 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.49 $ $NHDT-Date: 1560089250 2019/06/09 14:07:30 $ This fixes36.3 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.2 in May 2019. Please note, however, @@ -109,6 +109,8 @@ curses: don't convert ^M (or or key) into ^J; both ^J and ^M commands, ^J means run toward bottom of screen (when number_pad is off) and ^M is not bound to any command, so accidental won't cause the hero to try to move +curses+EDIT_GETLIN: when a prompt's answer was preloaded, using ESC to discard + it deleted it from the answer buffer but didn't erase it from screen tty: re-do one optimization used when status conditions have all been removed and remove another that tried to check whether condition text to be displayed next was the same as the existing value; sometimes new diff --git a/win/curses/cursmesg.c b/win/curses/cursmesg.c index d752223fa..992d5741f 100644 --- a/win/curses/cursmesg.c +++ b/win/curses/cursmesg.c @@ -469,7 +469,7 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer) int maxy, maxx; /* linewrap / scroll */ int ch; int border_space = 0; - int len; /* of answer string */ + int ltmp, len; /* of answer string */ boolean border = curses_window_has_border(MESSAGE_WIN); WINDOW *win = curses_get_nhwin(MESSAGE_WIN); @@ -531,9 +531,30 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer) my--; } } - mvwaddstr(win, my, mx, linestarts[nlines - 1]); - mx = promptx = (int) strlen(linestarts[nlines - 1]) + border_space; promptline = nlines - 1; + mvwaddstr(win, my, mx, linestarts[promptline]); + ltmp = (int) strlen(linestarts[promptline]); + mx = promptx = ltmp + border_space; +#ifdef EDIT_GETLIN + if (len <= ltmp) { + /* preloaded answer fits on same line as [last line of] prompt */ + promptx -= len; + } else { + int ltmp2 = len; + + /* preloaded answer spans lines so will be trickier to erase + if that is called for; find where the end of the prompt will + be without the answer appended */ + while (ltmp2 > 0) { + ltmp2 -= ltmp; + promptline -= 1; + ltmp = (int) strlen(linestarts[promptline]); + } + if (ltmp2 < 0) + ltmp = -ltmp2; + promptx = ltmp + border_space; + } +#endif while (1) { mx = (int) strlen(linestarts[nlines - 1]) + border_space;