MCPcopy Create free account
hub / github.com/NetHack/NetHack / tty_end_menu

Function tty_end_menu

win/tty/wintty.c:2648–2772  ·  view source on GitHub ↗

* End a menu in this window, window must a type NHW_MENU. This routine * processes the string list. We calculate the # of pages, then assign * keyboard accelerators as needed. Finally we decide on the width and * height of the window. */

Source from the content-addressed store, hash-verified

2646 * height of the window.
2647 */
2648void
2649tty_end_menu(
2650 winid window, /* menu to use */
2651 const char *prompt) /* prompt to for menu */
2652{
2653 struct WinDesc *cw = 0;
2654 tty_menu_item *curr;
2655 short len;
2656 int lmax, n;
2657 char menu_ch;
2658 int clr = NO_COLOR;
2659
2660 if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0
2661 || cw->type != NHW_MENU) {
2662 /* this can happen if start_menu failed due to size requirements
2663 for the tty perm inventory window. It isn't a situation that
2664 requires a panic, just an early return. */
2665 if (window == WIN_INVEN && !cw)
2666 return;
2667 ttywindowpanic();
2668 }
2669#ifdef TTY_PERM_INVENT
2670 /* (probably don't need to check both of these conditions) */
2671 if (cw->mbehavior == MENU_BEHAVE_PERMINV && window == WIN_INVEN) {
2672 ttyinv_end_menu(window, cw);
2673 return;
2674 }
2675#endif
2676
2677 /* Reverse the list so that items are in correct order. */
2678 cw->mlist = reverse(cw->mlist);
2679
2680 /* Put the prompt at the beginning of the menu. */
2681 if (prompt) {
2682 anything any;
2683
2684 any = cg.zeroany; /* not selectable */
2685 tty_add_menu(window, &nul_glyphinfo, &any, 0, 0,
2686 ATR_NONE, clr, "", MENU_ITEMFLAGS_NONE);
2687 tty_add_menu(window, &nul_glyphinfo, &any, 0, 0,
2688 tty_menu_promptstyle.attr, tty_menu_promptstyle.color,
2689 prompt, MENU_ITEMFLAGS_NONE);
2690 }
2691
2692 /* 52: 'a'..'z' and 'A'..'Z'; avoids selector duplication within a page */
2693 lmax = min(52, (int) ttyDisplay->rows - 1); /* # lines per page */
2694 cw->npages = (cw->nitems + (lmax - 1)) / lmax; /* # of pages */
2695 /*
2696 * TODO?
2697 * For really tall page, allow 53 if '$' or '#' is present and
2698 * 54 if both are. [Only for single page menu, otherwise pages
2699 * without those could try to use too many letters.]
2700 * Probably not worth bothering with; anyone with a display big
2701 * for this to matter will likely switch from tty to curses for
2702 * multi-line message window and/or persistent inventory window.
2703 */
2704
2705 /* make sure page list is large enough */

Callers

nothing calls this directly

Calls 5

ttyinv_end_menuFunction · 0.85
reverseFunction · 0.85
tty_add_menuFunction · 0.85
dupstrFunction · 0.85
allocFunction · 0.50

Tested by

no test coverage detected