Restoring a game can return to the wishing prompt

In TTY or curses, if the terminal goes away while you're in the wishing
prompt, return to the prompt when the game is restored.

Breaks saves.
This commit is contained in:
Pasi Kallinen
2025-07-12 18:21:09 +03:00
parent 65774372e6
commit e240efa10b
11 changed files with 28 additions and 2 deletions

View File

@@ -2453,6 +2453,8 @@ tty: hide cursor unless waiting for user input; now extended to include tty
platforms that define NO_TERMS, rather than just on those using
termcap/terminfo, namely Windows console and msdos (text-mode
implemented; vga and vesa just have stubs currently)
tty+curses: if terminal goes away while in the wishing prompt, return to the
wish prompt when game is restored
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)

View File

@@ -161,6 +161,7 @@ struct context_info {
boolean mv;
boolean bypasses; /* bypass flag is set on at least one fobj */
boolean door_opened; /* set to true if door was opened during test_move */
boolean resume_wish; /* game was exited while in wish prompt */
boolean tips[NUM_TIPS];
struct dig_info digging;
struct victual_info victual;

View File

@@ -246,6 +246,7 @@ struct instance_flags {
boolean invis_goldsym; /* gold symbol is ' '? */
boolean in_lua; /* executing a lua script */
boolean lua_testing; /* doing lua tests */
boolean term_gone; /* terminal is gone, abort abort abort */
boolean nofollowers; /* level change ignores pets (for tutorial) */
boolean partly_eaten_hack; /* extra flag for xname() used when it's called
* indirectly so we can't use xname_flags() */

View File

@@ -17,7 +17,7 @@
* Incrementing EDITLEVEL can be used to force invalidation of old bones
* and save files.
*/
#define EDITLEVEL 127
#define EDITLEVEL 128
/*
* Development status possibilities.

View File

@@ -187,6 +187,9 @@ moveloop_core(void)
if (iflags.sanity_check || iflags.debug_fuzzer)
sanity_check();
if (svc.context.resume_wish)
makewish(); /* clears resume_wish */
if (svc.context.move) {
/* actual time passed */
u.umovement -= NORMAL_SPEED;

View File

@@ -6186,6 +6186,7 @@ makewish(void)
int tries = 0;
long oldwisharti = u.uconduct.wisharti;
svc.context.resume_wish = 0;
promptbuf[0] = '\0';
nothing = cg.zeroobj; /* lint suppression; only its address matters */
if (flags.verbose)
@@ -6196,6 +6197,12 @@ makewish(void)
Strcat(promptbuf, " (enter 'help' for assistance)");
Strcat(promptbuf, "?");
getlin(promptbuf, buf);
if (iflags.term_gone) {
svc.context.resume_wish = 1;
return;
}
(void) mungspaces(buf);
if (buf[0] == '\033') {
buf[0] = '\0';

View File

@@ -308,6 +308,7 @@ curses_character_input_dialog(
answer = curses_read_char();
#endif
if (answer == ERR) {
iflags.term_gone = 1;
answer = def;
break;
}
@@ -451,6 +452,8 @@ curses_ext_cmd(void)
curs_set(0);
prompt_width = (int) strlen(cur_choice);
if (letter == ERR)
iflags.term_gone = 1;
if (letter == '\033' || letter == ERR) {
ret = -1;
break;
@@ -1518,6 +1521,7 @@ menu_get_selections(WINDOW *win, nhmenu *menu, int how)
curletter = curses_getch();
if (curletter == ERR) {
iflags.term_gone = 1;
num_selected = -1;
dismiss = TRUE;
}

View File

@@ -348,6 +348,8 @@ curses_block(
ret = '\n';
else
ret = curses_read_char();
if (ret == ERR)
iflags.term_gone = 1;
if (ret == ERR || ret == '\0')
ret = '\n';
/* msgtype=stop should require space/enter rather than any key,
@@ -775,6 +777,7 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
switch (ch) {
case ERR: /* should not happen */
iflags.term_gone = 1;
*answer = '\0';
goto alldone;
case '\033': /* DOESCAPE */

View File

@@ -1026,6 +1026,7 @@ parse_escape_sequence(int key, boolean *keypadnum)
ret = getch();
if (ret == ERR) {
iflags.term_gone = 1;
/* there was no additional char; treat as M-O or M-^O below */
ret = (key == '\033') ? 'O' : C('O');
} else if (ret >= 112 && ret <= 121) { /* 'p'..'y' */

View File

@@ -83,6 +83,8 @@ hooked_tty_getlin(
c = pgetchar();
term_curs_set(0);
if (c == '\033' || c == EOF) {
if (c == EOF)
iflags.term_gone = 1;
if (c == '\033' && obufp[0] != '\0') {
obufp[0] = '\0';
bufp = obufp;

View File

@@ -4090,8 +4090,10 @@ tty_nhgetch(void)
term_curs_set(0);
if (!i)
i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */
else if (i == EOF)
else if (i == EOF) {
iflags.term_gone = 1;
i = '\033'; /* same for EOF */
}
/* topline has been seen - we can clear the need for --More-- */
if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE)
ttyDisplay->toplin = TOPLINE_NON_EMPTY;