MCPcopy Index your code
hub / github.com/NetHack/NetHack / tty_yn_function

Function tty_yn_function

win/tty/topl.c:364–551  ·  view source on GitHub ↗

returns a single keystroke; also sets 'yn_number' */

Source from the content-addressed store, hash-verified

362
363/* returns a single keystroke; also sets 'yn_number' */
364char
365tty_yn_function(
366 const char *query,
367 const char *resp,
368 char def)
369{
370 /*
371 * Generic yes/no function. 'def' is the default (returned by space
372 * or return; 'esc' returns 'q', or 'n', or the default, depending on
373 * what's in the expected-response string. The 'query' string is
374 * printed before the user is asked about the string.
375 *
376 * If resp is NULL, any single character is accepted and returned.
377 * If not-NULL, only characters in it are allowed (exceptions: the
378 * quitchars are always allowed, and if it contains '#' then digits
379 * are allowed). If it includes an <esc>, anything beyond that won't
380 * be shown in the prompt to the user but will be acceptable as input.
381 */
382 char q;
383 char rtmp[40];
384 boolean digit_ok, allow_num, preserve_case = FALSE;
385 struct WinDesc *cw = wins[WIN_MESSAGE];
386 boolean doprev = 0;
387 char prompt[BUFSZ];
388
389 yn_number = 0L;
390 if (ttyDisplay->toplin == TOPLINE_NEED_MORE
391 && (cw->flags & (WIN_STOP | WIN_NOSTOP)) != WIN_STOP)
392 more();
393 cw->flags &= ~(WIN_STOP | WIN_NOSTOP);
394 ttyDisplay->toplin = TOPLINE_SPECIAL_PROMPT;
395 ttyDisplay->inread++;
396 if (resp) {
397 char *rb, respbuf[QBUFSZ];
398
399 allow_num = (strchr(resp, '#') != 0);
400 Strcpy(respbuf, resp);
401 /* normally we force lowercase, but if any uppercase letters
402 are present in the allowed response, preserve case;
403 check this before stripping the hidden choices */
404 for (rb = respbuf; *rb; ++rb)
405 if ('A' <= *rb && *rb <= 'Z') {
406 preserve_case = TRUE;
407 break;
408 }
409 /* any acceptable responses that follow <esc> aren't displayed */
410 if ((rb = strchr(respbuf, '\033')) != 0)
411 *rb = '\0';
412 (void) strncpy(prompt, query, QBUFSZ - 1);
413 prompt[QBUFSZ - 1] = '\0';
414 Sprintf(eos(prompt), " [%s]", respbuf);
415 if (def)
416 Sprintf(eos(prompt), " (%c)", def);
417 /* not pline("%s ", prompt);
418 trailing space is wanted here in case of reprompt */
419 Strcat(prompt, " ");
420 custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s", prompt);
421 } else {

Callers

nothing calls this directly

Calls 13

eosFunction · 0.85
customplineFunction · 0.85
readcharFunction · 0.85
tty_doprev_messageFunction · 0.85
tty_clear_nhwindowFunction · 0.85
addtoplFunction · 0.85
digitFunction · 0.85
key2txtFunction · 0.85
dumplogmsgFunction · 0.85
moreFunction · 0.70
tty_nhbellFunction · 0.70
removetoplFunction · 0.70

Tested by

no test coverage detected