162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  menubox.c -- implements the menu box
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *  ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
662306a36Sopenharmony_ci *  MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com)
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/*
1062306a36Sopenharmony_ci *  Changes by Clifford Wolf (god@clifford.at)
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci *  [ 1998-06-13 ]
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci *    *)  A bugfix for the Page-Down problem
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci *    *)  Formerly when I used Page Down and Page Up, the cursor would be set
1762306a36Sopenharmony_ci *        to the first position in the menu box.  Now lxdialog is a bit
1862306a36Sopenharmony_ci *        smarter and works more like other menu systems (just have a look at
1962306a36Sopenharmony_ci *        it).
2062306a36Sopenharmony_ci *
2162306a36Sopenharmony_ci *    *)  Formerly if I selected something my scrolling would be broken because
2262306a36Sopenharmony_ci *        lxdialog is re-invoked by the Menuconfig shell script, can't
2362306a36Sopenharmony_ci *        remember the last scrolling position, and just sets it so that the
2462306a36Sopenharmony_ci *        cursor is at the bottom of the box.  Now it writes the temporary file
2562306a36Sopenharmony_ci *        lxdialog.scrltmp which contains this information. The file is
2662306a36Sopenharmony_ci *        deleted by lxdialog if the user leaves a submenu or enters a new
2762306a36Sopenharmony_ci *        one, but it would be nice if Menuconfig could make another "rm -f"
2862306a36Sopenharmony_ci *        just to be sure.  Just try it out - you will recognise a difference!
2962306a36Sopenharmony_ci *
3062306a36Sopenharmony_ci *  [ 1998-06-14 ]
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci *    *)  Now lxdialog is crash-safe against broken "lxdialog.scrltmp" files
3362306a36Sopenharmony_ci *        and menus change their size on the fly.
3462306a36Sopenharmony_ci *
3562306a36Sopenharmony_ci *    *)  If for some reason the last scrolling position is not saved by
3662306a36Sopenharmony_ci *        lxdialog, it sets the scrolling so that the selected item is in the
3762306a36Sopenharmony_ci *        middle of the menu box, not at the bottom.
3862306a36Sopenharmony_ci *
3962306a36Sopenharmony_ci * 02 January 1999, Michael Elizabeth Chastain (mec@shout.net)
4062306a36Sopenharmony_ci * Reset 'scroll' to 0 if the value from lxdialog.scrltmp is bogus.
4162306a36Sopenharmony_ci * This fixes a bug in Menuconfig where using ' ' to descend into menus
4262306a36Sopenharmony_ci * would leave mis-synchronized lxdialog.scrltmp files lying around,
4362306a36Sopenharmony_ci * fscanf would read in 'scroll', and eventually that value would get used.
4462306a36Sopenharmony_ci */
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#include "dialog.h"
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cistatic int menu_width, item_x;
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/*
5162306a36Sopenharmony_ci * Print menu item
5262306a36Sopenharmony_ci */
5362306a36Sopenharmony_cistatic void do_print_item(WINDOW * win, const char *item, int line_y,
5462306a36Sopenharmony_ci			  int selected, int hotkey)
5562306a36Sopenharmony_ci{
5662306a36Sopenharmony_ci	int j;
5762306a36Sopenharmony_ci	char *menu_item = malloc(menu_width + 1);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	strncpy(menu_item, item, menu_width - item_x);
6062306a36Sopenharmony_ci	menu_item[menu_width - item_x] = '\0';
6162306a36Sopenharmony_ci	j = first_alpha(menu_item, "YyNnMmHh");
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	/* Clear 'residue' of last item */
6462306a36Sopenharmony_ci	wattrset(win, dlg.menubox.atr);
6562306a36Sopenharmony_ci	wmove(win, line_y, 0);
6662306a36Sopenharmony_ci	wclrtoeol(win);
6762306a36Sopenharmony_ci	wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
6862306a36Sopenharmony_ci	mvwaddstr(win, line_y, item_x, menu_item);
6962306a36Sopenharmony_ci	if (hotkey) {
7062306a36Sopenharmony_ci		wattrset(win, selected ? dlg.tag_key_selected.atr
7162306a36Sopenharmony_ci			 : dlg.tag_key.atr);
7262306a36Sopenharmony_ci		mvwaddch(win, line_y, item_x + j, menu_item[j]);
7362306a36Sopenharmony_ci	}
7462306a36Sopenharmony_ci	if (selected) {
7562306a36Sopenharmony_ci		wmove(win, line_y, item_x + 1);
7662306a36Sopenharmony_ci	}
7762306a36Sopenharmony_ci	free(menu_item);
7862306a36Sopenharmony_ci	wrefresh(win);
7962306a36Sopenharmony_ci}
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define print_item(index, choice, selected)				\
8262306a36Sopenharmony_cido {									\
8362306a36Sopenharmony_ci	item_set(index);						\
8462306a36Sopenharmony_ci	do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \
8562306a36Sopenharmony_ci} while (0)
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/*
8862306a36Sopenharmony_ci * Print the scroll indicators.
8962306a36Sopenharmony_ci */
9062306a36Sopenharmony_cistatic void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
9162306a36Sopenharmony_ci			 int height)
9262306a36Sopenharmony_ci{
9362306a36Sopenharmony_ci	int cur_y, cur_x;
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci	getyx(win, cur_y, cur_x);
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci	wmove(win, y, x);
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci	if (scroll > 0) {
10062306a36Sopenharmony_ci		wattrset(win, dlg.uarrow.atr);
10162306a36Sopenharmony_ci		waddch(win, ACS_UARROW);
10262306a36Sopenharmony_ci		waddstr(win, "(-)");
10362306a36Sopenharmony_ci	} else {
10462306a36Sopenharmony_ci		wattrset(win, dlg.menubox.atr);
10562306a36Sopenharmony_ci		waddch(win, ACS_HLINE);
10662306a36Sopenharmony_ci		waddch(win, ACS_HLINE);
10762306a36Sopenharmony_ci		waddch(win, ACS_HLINE);
10862306a36Sopenharmony_ci		waddch(win, ACS_HLINE);
10962306a36Sopenharmony_ci	}
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci	y = y + height + 1;
11262306a36Sopenharmony_ci	wmove(win, y, x);
11362306a36Sopenharmony_ci	wrefresh(win);
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci	if ((height < item_no) && (scroll + height < item_no)) {
11662306a36Sopenharmony_ci		wattrset(win, dlg.darrow.atr);
11762306a36Sopenharmony_ci		waddch(win, ACS_DARROW);
11862306a36Sopenharmony_ci		waddstr(win, "(+)");
11962306a36Sopenharmony_ci	} else {
12062306a36Sopenharmony_ci		wattrset(win, dlg.menubox_border.atr);
12162306a36Sopenharmony_ci		waddch(win, ACS_HLINE);
12262306a36Sopenharmony_ci		waddch(win, ACS_HLINE);
12362306a36Sopenharmony_ci		waddch(win, ACS_HLINE);
12462306a36Sopenharmony_ci		waddch(win, ACS_HLINE);
12562306a36Sopenharmony_ci	}
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci	wmove(win, cur_y, cur_x);
12862306a36Sopenharmony_ci	wrefresh(win);
12962306a36Sopenharmony_ci}
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci/*
13262306a36Sopenharmony_ci * Display the termination buttons.
13362306a36Sopenharmony_ci */
13462306a36Sopenharmony_cistatic void print_buttons(WINDOW * win, int height, int width, int selected)
13562306a36Sopenharmony_ci{
13662306a36Sopenharmony_ci	int x = width / 2 - 28;
13762306a36Sopenharmony_ci	int y = height - 2;
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci	print_button(win, "Select", y, x, selected == 0);
14062306a36Sopenharmony_ci	print_button(win, " Exit ", y, x + 12, selected == 1);
14162306a36Sopenharmony_ci	print_button(win, " Help ", y, x + 24, selected == 2);
14262306a36Sopenharmony_ci	print_button(win, " Save ", y, x + 36, selected == 3);
14362306a36Sopenharmony_ci	print_button(win, " Load ", y, x + 48, selected == 4);
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci	wmove(win, y, x + 1 + 12 * selected);
14662306a36Sopenharmony_ci	wrefresh(win);
14762306a36Sopenharmony_ci}
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci/* scroll up n lines (n may be negative) */
15062306a36Sopenharmony_cistatic void do_scroll(WINDOW *win, int *scroll, int n)
15162306a36Sopenharmony_ci{
15262306a36Sopenharmony_ci	/* Scroll menu up */
15362306a36Sopenharmony_ci	scrollok(win, TRUE);
15462306a36Sopenharmony_ci	wscrl(win, n);
15562306a36Sopenharmony_ci	scrollok(win, FALSE);
15662306a36Sopenharmony_ci	*scroll = *scroll + n;
15762306a36Sopenharmony_ci	wrefresh(win);
15862306a36Sopenharmony_ci}
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci/*
16162306a36Sopenharmony_ci * Display a menu for choosing among a number of options
16262306a36Sopenharmony_ci */
16362306a36Sopenharmony_ciint dialog_menu(const char *title, const char *prompt,
16462306a36Sopenharmony_ci		const void *selected, int *s_scroll)
16562306a36Sopenharmony_ci{
16662306a36Sopenharmony_ci	int i, j, x, y, box_x, box_y;
16762306a36Sopenharmony_ci	int height, width, menu_height;
16862306a36Sopenharmony_ci	int key = 0, button = 0, scroll = 0, choice = 0;
16962306a36Sopenharmony_ci	int first_item =  0, max_choice;
17062306a36Sopenharmony_ci	WINDOW *dialog, *menu;
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_cido_resize:
17362306a36Sopenharmony_ci	height = getmaxy(stdscr);
17462306a36Sopenharmony_ci	width = getmaxx(stdscr);
17562306a36Sopenharmony_ci	if (height < MENUBOX_HEIGTH_MIN || width < MENUBOX_WIDTH_MIN)
17662306a36Sopenharmony_ci		return -ERRDISPLAYTOOSMALL;
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci	height -= 4;
17962306a36Sopenharmony_ci	width  -= 5;
18062306a36Sopenharmony_ci	menu_height = height - 10;
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci	max_choice = MIN(menu_height, item_count());
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci	/* center dialog box on screen */
18562306a36Sopenharmony_ci	x = (getmaxx(stdscr) - width) / 2;
18662306a36Sopenharmony_ci	y = (getmaxy(stdscr) - height) / 2;
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci	draw_shadow(stdscr, y, x, height, width);
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci	dialog = newwin(height, width, y, x);
19162306a36Sopenharmony_ci	keypad(dialog, TRUE);
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci	draw_box(dialog, 0, 0, height, width,
19462306a36Sopenharmony_ci		 dlg.dialog.atr, dlg.border.atr);
19562306a36Sopenharmony_ci	wattrset(dialog, dlg.border.atr);
19662306a36Sopenharmony_ci	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
19762306a36Sopenharmony_ci	for (i = 0; i < width - 2; i++)
19862306a36Sopenharmony_ci		waddch(dialog, ACS_HLINE);
19962306a36Sopenharmony_ci	wattrset(dialog, dlg.dialog.atr);
20062306a36Sopenharmony_ci	wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
20162306a36Sopenharmony_ci	waddch(dialog, ACS_RTEE);
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci	print_title(dialog, title, width);
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci	wattrset(dialog, dlg.dialog.atr);
20662306a36Sopenharmony_ci	print_autowrap(dialog, prompt, width - 2, 1, 3);
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci	menu_width = width - 6;
20962306a36Sopenharmony_ci	box_y = height - menu_height - 5;
21062306a36Sopenharmony_ci	box_x = (width - menu_width) / 2 - 1;
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci	/* create new window for the menu */
21362306a36Sopenharmony_ci	menu = subwin(dialog, menu_height, menu_width,
21462306a36Sopenharmony_ci		      y + box_y + 1, x + box_x + 1);
21562306a36Sopenharmony_ci	keypad(menu, TRUE);
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci	/* draw a box around the menu items */
21862306a36Sopenharmony_ci	draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
21962306a36Sopenharmony_ci		 dlg.menubox_border.atr, dlg.menubox.atr);
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci	if (menu_width >= 80)
22262306a36Sopenharmony_ci		item_x = (menu_width - 70) / 2;
22362306a36Sopenharmony_ci	else
22462306a36Sopenharmony_ci		item_x = 4;
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci	/* Set choice to default item */
22762306a36Sopenharmony_ci	item_foreach()
22862306a36Sopenharmony_ci		if (selected && (selected == item_data()))
22962306a36Sopenharmony_ci			choice = item_n();
23062306a36Sopenharmony_ci	/* get the saved scroll info */
23162306a36Sopenharmony_ci	scroll = *s_scroll;
23262306a36Sopenharmony_ci	if ((scroll <= choice) && (scroll + max_choice > choice) &&
23362306a36Sopenharmony_ci	   (scroll >= 0) && (scroll + max_choice <= item_count())) {
23462306a36Sopenharmony_ci		first_item = scroll;
23562306a36Sopenharmony_ci		choice = choice - scroll;
23662306a36Sopenharmony_ci	} else {
23762306a36Sopenharmony_ci		scroll = 0;
23862306a36Sopenharmony_ci	}
23962306a36Sopenharmony_ci	if ((choice >= max_choice)) {
24062306a36Sopenharmony_ci		if (choice >= item_count() - max_choice / 2)
24162306a36Sopenharmony_ci			scroll = first_item = item_count() - max_choice;
24262306a36Sopenharmony_ci		else
24362306a36Sopenharmony_ci			scroll = first_item = choice - max_choice / 2;
24462306a36Sopenharmony_ci		choice = choice - scroll;
24562306a36Sopenharmony_ci	}
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ci	/* Print the menu */
24862306a36Sopenharmony_ci	for (i = 0; i < max_choice; i++) {
24962306a36Sopenharmony_ci		print_item(first_item + i, i, i == choice);
25062306a36Sopenharmony_ci	}
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci	wnoutrefresh(menu);
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci	print_arrows(dialog, item_count(), scroll,
25562306a36Sopenharmony_ci		     box_y, box_x + item_x + 1, menu_height);
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci	print_buttons(dialog, height, width, 0);
25862306a36Sopenharmony_ci	wmove(menu, choice, item_x + 1);
25962306a36Sopenharmony_ci	wrefresh(menu);
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ci	while (key != KEY_ESC) {
26262306a36Sopenharmony_ci		key = wgetch(menu);
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci		if (key < 256 && isalpha(key))
26562306a36Sopenharmony_ci			key = tolower(key);
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci		if (strchr("ynmh", key))
26862306a36Sopenharmony_ci			i = max_choice;
26962306a36Sopenharmony_ci		else {
27062306a36Sopenharmony_ci			for (i = choice + 1; i < max_choice; i++) {
27162306a36Sopenharmony_ci				item_set(scroll + i);
27262306a36Sopenharmony_ci				j = first_alpha(item_str(), "YyNnMmHh");
27362306a36Sopenharmony_ci				if (key == tolower(item_str()[j]))
27462306a36Sopenharmony_ci					break;
27562306a36Sopenharmony_ci			}
27662306a36Sopenharmony_ci			if (i == max_choice)
27762306a36Sopenharmony_ci				for (i = 0; i < max_choice; i++) {
27862306a36Sopenharmony_ci					item_set(scroll + i);
27962306a36Sopenharmony_ci					j = first_alpha(item_str(), "YyNnMmHh");
28062306a36Sopenharmony_ci					if (key == tolower(item_str()[j]))
28162306a36Sopenharmony_ci						break;
28262306a36Sopenharmony_ci				}
28362306a36Sopenharmony_ci		}
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_ci		if (item_count() != 0 &&
28662306a36Sopenharmony_ci		    (i < max_choice ||
28762306a36Sopenharmony_ci		     key == KEY_UP || key == KEY_DOWN ||
28862306a36Sopenharmony_ci		     key == '-' || key == '+' ||
28962306a36Sopenharmony_ci		     key == KEY_PPAGE || key == KEY_NPAGE)) {
29062306a36Sopenharmony_ci			/* Remove highligt of current item */
29162306a36Sopenharmony_ci			print_item(scroll + choice, choice, FALSE);
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci			if (key == KEY_UP || key == '-') {
29462306a36Sopenharmony_ci				if (choice < 2 && scroll) {
29562306a36Sopenharmony_ci					/* Scroll menu down */
29662306a36Sopenharmony_ci					do_scroll(menu, &scroll, -1);
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci					print_item(scroll, 0, FALSE);
29962306a36Sopenharmony_ci				} else
30062306a36Sopenharmony_ci					choice = MAX(choice - 1, 0);
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_ci			} else if (key == KEY_DOWN || key == '+') {
30362306a36Sopenharmony_ci				print_item(scroll+choice, choice, FALSE);
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci				if ((choice > max_choice - 3) &&
30662306a36Sopenharmony_ci				    (scroll + max_choice < item_count())) {
30762306a36Sopenharmony_ci					/* Scroll menu up */
30862306a36Sopenharmony_ci					do_scroll(menu, &scroll, 1);
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_ci					print_item(scroll+max_choice - 1,
31162306a36Sopenharmony_ci						   max_choice - 1, FALSE);
31262306a36Sopenharmony_ci				} else
31362306a36Sopenharmony_ci					choice = MIN(choice + 1, max_choice - 1);
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci			} else if (key == KEY_PPAGE) {
31662306a36Sopenharmony_ci				scrollok(menu, TRUE);
31762306a36Sopenharmony_ci				for (i = 0; (i < max_choice); i++) {
31862306a36Sopenharmony_ci					if (scroll > 0) {
31962306a36Sopenharmony_ci						do_scroll(menu, &scroll, -1);
32062306a36Sopenharmony_ci						print_item(scroll, 0, FALSE);
32162306a36Sopenharmony_ci					} else {
32262306a36Sopenharmony_ci						if (choice > 0)
32362306a36Sopenharmony_ci							choice--;
32462306a36Sopenharmony_ci					}
32562306a36Sopenharmony_ci				}
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci			} else if (key == KEY_NPAGE) {
32862306a36Sopenharmony_ci				for (i = 0; (i < max_choice); i++) {
32962306a36Sopenharmony_ci					if (scroll + max_choice < item_count()) {
33062306a36Sopenharmony_ci						do_scroll(menu, &scroll, 1);
33162306a36Sopenharmony_ci						print_item(scroll+max_choice-1,
33262306a36Sopenharmony_ci							   max_choice - 1, FALSE);
33362306a36Sopenharmony_ci					} else {
33462306a36Sopenharmony_ci						if (choice + 1 < max_choice)
33562306a36Sopenharmony_ci							choice++;
33662306a36Sopenharmony_ci					}
33762306a36Sopenharmony_ci				}
33862306a36Sopenharmony_ci			} else
33962306a36Sopenharmony_ci				choice = i;
34062306a36Sopenharmony_ci
34162306a36Sopenharmony_ci			print_item(scroll + choice, choice, TRUE);
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ci			print_arrows(dialog, item_count(), scroll,
34462306a36Sopenharmony_ci				     box_y, box_x + item_x + 1, menu_height);
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_ci			wnoutrefresh(dialog);
34762306a36Sopenharmony_ci			wrefresh(menu);
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci			continue;	/* wait for another key press */
35062306a36Sopenharmony_ci		}
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ci		switch (key) {
35362306a36Sopenharmony_ci		case KEY_LEFT:
35462306a36Sopenharmony_ci		case TAB:
35562306a36Sopenharmony_ci		case KEY_RIGHT:
35662306a36Sopenharmony_ci			button = ((key == KEY_LEFT ? --button : ++button) < 0)
35762306a36Sopenharmony_ci			    ? 4 : (button > 4 ? 0 : button);
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci			print_buttons(dialog, height, width, button);
36062306a36Sopenharmony_ci			wrefresh(menu);
36162306a36Sopenharmony_ci			break;
36262306a36Sopenharmony_ci		case ' ':
36362306a36Sopenharmony_ci		case 's':
36462306a36Sopenharmony_ci		case 'y':
36562306a36Sopenharmony_ci		case 'n':
36662306a36Sopenharmony_ci		case 'm':
36762306a36Sopenharmony_ci		case '/':
36862306a36Sopenharmony_ci		case 'h':
36962306a36Sopenharmony_ci		case '?':
37062306a36Sopenharmony_ci		case 'z':
37162306a36Sopenharmony_ci		case '\n':
37262306a36Sopenharmony_ci			/* save scroll info */
37362306a36Sopenharmony_ci			*s_scroll = scroll;
37462306a36Sopenharmony_ci			delwin(menu);
37562306a36Sopenharmony_ci			delwin(dialog);
37662306a36Sopenharmony_ci			item_set(scroll + choice);
37762306a36Sopenharmony_ci			item_set_selected(1);
37862306a36Sopenharmony_ci			switch (key) {
37962306a36Sopenharmony_ci			case 'h':
38062306a36Sopenharmony_ci			case '?':
38162306a36Sopenharmony_ci				return 2;
38262306a36Sopenharmony_ci			case 's':
38362306a36Sopenharmony_ci			case 'y':
38462306a36Sopenharmony_ci				return 5;
38562306a36Sopenharmony_ci			case 'n':
38662306a36Sopenharmony_ci				return 6;
38762306a36Sopenharmony_ci			case 'm':
38862306a36Sopenharmony_ci				return 7;
38962306a36Sopenharmony_ci			case ' ':
39062306a36Sopenharmony_ci				return 8;
39162306a36Sopenharmony_ci			case '/':
39262306a36Sopenharmony_ci				return 9;
39362306a36Sopenharmony_ci			case 'z':
39462306a36Sopenharmony_ci				return 10;
39562306a36Sopenharmony_ci			case '\n':
39662306a36Sopenharmony_ci				return button;
39762306a36Sopenharmony_ci			}
39862306a36Sopenharmony_ci			return 0;
39962306a36Sopenharmony_ci		case 'e':
40062306a36Sopenharmony_ci		case 'x':
40162306a36Sopenharmony_ci			key = KEY_ESC;
40262306a36Sopenharmony_ci			break;
40362306a36Sopenharmony_ci		case KEY_ESC:
40462306a36Sopenharmony_ci			key = on_key_esc(menu);
40562306a36Sopenharmony_ci			break;
40662306a36Sopenharmony_ci		case KEY_RESIZE:
40762306a36Sopenharmony_ci			on_key_resize();
40862306a36Sopenharmony_ci			delwin(menu);
40962306a36Sopenharmony_ci			delwin(dialog);
41062306a36Sopenharmony_ci			goto do_resize;
41162306a36Sopenharmony_ci		}
41262306a36Sopenharmony_ci	}
41362306a36Sopenharmony_ci	delwin(menu);
41462306a36Sopenharmony_ci	delwin(dialog);
41562306a36Sopenharmony_ci	return key;		/* ESC pressed */
41662306a36Sopenharmony_ci}
417