menubox.c revision 59d3cf7a40dfdbb8e86758ade172831c19630050
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  menubox.c -- implements the menu box
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com)
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  This program is free software; you can redistribute it and/or
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  modify it under the terms of the GNU General Public License
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  as published by the Free Software Foundation; either version 2
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  of the License, or (at your option) any later version.
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  This program is distributed in the hope that it will be useful,
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  but WITHOUT ANY WARRANTY; without even the implied warranty of
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  GNU General Public License for more details.
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  You should have received a copy of the GNU General Public License
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  along with this program; if not, write to the Free Software
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  Changes by Clifford Wolf (god@clifford.at)
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  [ 1998-06-13 ]
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    *)  A bugfix for the Page-Down problem
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    *)  Formerly when I used Page Down and Page Up, the cursor would be set
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        to the first position in the menu box.  Now lxdialog is a bit
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        smarter and works more like other menu systems (just have a look at
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        it).
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    *)  Formerly if I selected something my scrolling would be broken because
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        lxdialog is re-invoked by the Menuconfig shell script, can't
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        remember the last scrolling position, and just sets it so that the
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        cursor is at the bottom of the box.  Now it writes the temporary file
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        lxdialog.scrltmp which contains this information. The file is
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        deleted by lxdialog if the user leaves a submenu or enters a new
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        one, but it would be nice if Menuconfig could make another "rm -f"
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        just to be sure.  Just try it out - you will recognise a difference!
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  [ 1998-06-14 ]
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    *)  Now lxdialog is crash-safe against broken "lxdialog.scrltmp" files
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        and menus change their size on the fly.
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *    *)  If for some reason the last scrolling position is not saved by
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        lxdialog, it sets the scrolling so that the selected item is in the
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *        middle of the menu box, not at the bottom.
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 02 January 1999, Michael Elizabeth Chastain (mec@shout.net)
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Reset 'scroll' to 0 if the value from lxdialog.scrltmp is bogus.
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This fixes a bug in Menuconfig where using ' ' to descend into menus
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * would leave mis-synchronized lxdialog.scrltmp files lying around,
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fscanf would read in 'scroll', and eventually that value would get used.
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "dialog.h"
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
610e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg#define ITEM_IDENT 4   /* Indent of menu entries. Fixed for all menus */
620e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborgstatic int menu_width;
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Print menu item
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
6759d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborgstatic void do_print_item(WINDOW * win, const char *item, int choice,
6859d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg                          int selected, int hotkey)
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
70b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	int j;
71a06104af7dcf2f5bafaf18f373c8b2554cbfe014Sam Ravnborg	char *menu_item = malloc(menu_width + 1);
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
73b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	strncpy(menu_item, item, menu_width);
74b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	menu_item[menu_width] = 0;
75b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	j = first_alpha(menu_item, "YyNnMmHh");
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
77b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	/* Clear 'residue' of last item */
78b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wattrset(win, menubox_attr);
79b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wmove(win, choice, 0);
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if OLD_NCURSES
81b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	{
82b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		int i;
83b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		for (i = 0; i < menu_width; i++)
84b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			waddch(win, ' ');
85b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	}
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
87b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wclrtoeol(win);
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
89b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wattrset(win, selected ? item_selected_attr : item_attr);
900e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg	mvwaddstr(win, choice, ITEM_IDENT, menu_item);
91b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	if (hotkey) {
92b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		wattrset(win, selected ? tag_key_selected_attr : tag_key_attr);
930e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg		mvwaddch(win, choice, ITEM_IDENT + j, menu_item[j]);
94b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	}
95b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	if (selected) {
960e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg		wmove(win, choice, ITEM_IDENT + 1);
97b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	}
98a06104af7dcf2f5bafaf18f373c8b2554cbfe014Sam Ravnborg	free(menu_item);
997c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg	wrefresh(win);
1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10259d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg#define print_item(index, choice, selected) \
10359d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborgdo {\
10459d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg	int hotkey = (items[(index) * 2][0] != ':'); \
10559d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg	do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \
10659d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg} while (0)
10759d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Print the scroll indicators.
1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
111dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborgstatic void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
112dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg			 int height)
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
114b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	int cur_y, cur_x;
115b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
116b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	getyx(win, cur_y, cur_x);
117b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
118b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wmove(win, y, x);
119b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
120b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	if (scroll > 0) {
121b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		wattrset(win, uarrow_attr);
122b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_UARROW);
123b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddstr(win, "(-)");
124b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	} else {
125b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		wattrset(win, menubox_attr);
126b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_HLINE);
127b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_HLINE);
128b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_HLINE);
129b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_HLINE);
130b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	}
131b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
132b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	y = y + height + 1;
133b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wmove(win, y, x);
1347c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg	wrefresh(win);
135b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
136b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	if ((height < item_no) && (scroll + height < item_no)) {
137b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		wattrset(win, darrow_attr);
138b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_DARROW);
139b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddstr(win, "(+)");
140b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	} else {
141b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		wattrset(win, menubox_border_attr);
142b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_HLINE);
143b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_HLINE);
144b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_HLINE);
145b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(win, ACS_HLINE);
146b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	}
147b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
148b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wmove(win, cur_y, cur_x);
1497c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg	wrefresh(win);
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Display the termination buttons.
1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
155b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborgstatic void print_buttons(WINDOW * win, int height, int width, int selected)
1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
157b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	int x = width / 2 - 16;
158b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	int y = height - 2;
1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
160b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	print_button(win, "Select", y, x, selected == 0);
161b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	print_button(win, " Exit ", y, x + 12, selected == 1);
162b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	print_button(win, " Help ", y, x + 24, selected == 2);
1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
164b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wmove(win, y, x + 1 + 12 * selected);
165b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wrefresh(win);
1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1687c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg/* scroll up n lines (n may be negative) */
1697c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborgstatic void do_scroll(WINDOW *win, int *scroll, int n)
1707c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg{
1717c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg	/* Scroll menu up */
1727c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg	scrollok(win, TRUE);
1737c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg	wscrl(win, n);
1747c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg	scrollok(win, FALSE);
1757c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg	*scroll = *scroll + n;
1767c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg	wrefresh(win);
1777c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg}
1787c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg
1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Display a menu for choosing among a number of options
1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
182dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborgint dialog_menu(const char *title, const char *prompt, int height, int width,
183dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg                int menu_height, const char *current, int item_no,
184dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg                const char *const *items)
1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
186b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	int i, j, x, y, box_x, box_y;
187b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	int key = 0, button = 0, scroll = 0, choice = 0, first_item =
188b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	    0, max_choice;
189b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	WINDOW *dialog, *menu;
190b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	FILE *f;
191b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
192b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	max_choice = MIN(menu_height, item_no);
193b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
194b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	/* center dialog box on screen */
195b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	x = (COLS - width) / 2;
196b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	y = (LINES - height) / 2;
197b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
198b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	draw_shadow(stdscr, y, x, height, width);
199b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
200b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	dialog = newwin(height, width, y, x);
201b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	keypad(dialog, TRUE);
202b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
203b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
204b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wattrset(dialog, border_attr);
205b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
206b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	for (i = 0; i < width - 2; i++)
207b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		waddch(dialog, ACS_HLINE);
208b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wattrset(dialog, dialog_attr);
209b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wbkgdset(dialog, dialog_attr & A_COLOR);
210b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	waddch(dialog, ACS_RTEE);
211b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
212fa7009d5b59b8acd8071f7b3057d36eeeaf08146Sam Ravnborg	print_title(dialog, title, width);
213b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
214b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wattrset(dialog, dialog_attr);
215b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	print_autowrap(dialog, prompt, width - 2, 1, 3);
216b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
217b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	menu_width = width - 6;
218b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	box_y = height - menu_height - 5;
219b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	box_x = (width - menu_width) / 2 - 1;
220b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
221b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	/* create new window for the menu */
222b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	menu = subwin(dialog, menu_height, menu_width,
223b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		      y + box_y + 1, x + box_x + 1);
224b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	keypad(menu, TRUE);
225b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
226b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	/* draw a box around the menu items */
227b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
228b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		 menubox_border_attr, menubox_attr);
229b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
2300e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg	/* Set choice to default item */
2310e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg	for (i = 0; i < item_no; i++)
232b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		if (strcmp(current, items[i * 2]) == 0)
233b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			choice = i;
234b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
235b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	/* get the scroll info from the temp file */
236b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) {
237b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) &&
238b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		    (scroll + max_choice > choice) && (scroll >= 0) &&
239b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		    (scroll + max_choice <= item_no)) {
240b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			first_item = scroll;
241b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			choice = choice - scroll;
242b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			fclose(f);
243b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		} else {
244b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			scroll = 0;
245b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			remove("lxdialog.scrltmp");
246b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			fclose(f);
247b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			f = NULL;
2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
250b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) {
251b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		if (choice >= item_no - max_choice / 2)
252b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			scroll = first_item = item_no - max_choice;
253b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		else
254b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			scroll = first_item = choice - max_choice / 2;
255b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		choice = choice - scroll;
256b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	}
2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
258b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	/* Print the menu */
259b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	for (i = 0; i < max_choice; i++) {
26059d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg		print_item(first_item + i, i, i == choice);
261b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	}
262b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
263b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wnoutrefresh(menu);
264b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
265b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	print_arrows(dialog, item_no, scroll,
2660e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg		     box_y, box_x + ITEM_IDENT + 1, menu_height);
267b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
268b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	print_buttons(dialog, height, width, 0);
2690e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg	wmove(menu, choice, ITEM_IDENT + 1);
270b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	wrefresh(menu);
271b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
272b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	while (key != ESC) {
273b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		key = wgetch(menu);
274b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
275b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		if (key < 256 && isalpha(key))
276b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			key = tolower(key);
277b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
278b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		if (strchr("ynmh", key))
279b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			i = max_choice;
280b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		else {
281b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			for (i = choice + 1; i < max_choice; i++) {
282dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg				j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh");
283dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg				if (key == tolower(items[(scroll + i) * 2 + 1][j]))
284b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					break;
285b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			}
286b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			if (i == max_choice)
287b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				for (i = 0; i < max_choice; i++) {
288dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg					j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh");
289dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg					if (key == tolower(items[(scroll + i) * 2 + 1][j]))
290b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg						break;
291b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				}
292b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		}
293b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
294b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		if (i < max_choice ||
295b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		    key == KEY_UP || key == KEY_DOWN ||
296b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		    key == '-' || key == '+' ||
297b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		    key == KEY_PPAGE || key == KEY_NPAGE) {
2980e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg			/* Remove highligt of current item */
29959d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg			print_item(scroll + choice, choice, FALSE);
300b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
301b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			if (key == KEY_UP || key == '-') {
302b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				if (choice < 2 && scroll) {
303b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					/* Scroll menu down */
3047c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg					do_scroll(menu, &scroll, -1);
305b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
30659d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg					print_item(scroll, 0, FALSE);
307b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				} else
308b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					choice = MAX(choice - 1, 0);
309b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
310b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			} else if (key == KEY_DOWN || key == '+') {
31159d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg				print_item(scroll+choice, choice, FALSE);
312b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
313b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				if ((choice > max_choice - 3) &&
314dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg				    (scroll + max_choice < item_no)) {
315b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					/* Scroll menu up */
3167c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg					do_scroll(menu, &scroll, 1);
317b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
31859d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg					print_item(scroll+max_choice - 1,
31959d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg						   max_choice - 1, FALSE);
320b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				} else
321dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg					choice = MIN(choice + 1, max_choice - 1);
322b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
323b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			} else if (key == KEY_PPAGE) {
324b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				scrollok(menu, TRUE);
325b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				for (i = 0; (i < max_choice); i++) {
326b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					if (scroll > 0) {
3277c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg						do_scroll(menu, &scroll, -1);
32859d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg						print_item(scroll, 0, FALSE);
329b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					} else {
330b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg						if (choice > 0)
331b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg							choice--;
332b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					}
333b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				}
334b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
335b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			} else if (key == KEY_NPAGE) {
336b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				for (i = 0; (i < max_choice); i++) {
337b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					if (scroll + max_choice < item_no) {
3387c3badf96e0dc8aa89ebf8919653339a5ee8e035Sam Ravnborg						do_scroll(menu, &scroll, 1);
33959d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg						print_item(scroll+max_choice-1,
34059d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg							   max_choice - 1, FALSE);
341b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					} else {
342b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg						if (choice + 1 < max_choice)
343b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg							choice++;
344b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					}
345b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				}
346b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			} else
347b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				choice = i;
348b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
34959d3cf7a40dfdbb8e86758ade172831c19630050Sam Ravnborg			print_item(scroll + choice, choice, TRUE);
350b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
351b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			print_arrows(dialog, item_no, scroll,
3520e175d05a4e72f85918da3ea4bd9f5d3d78face4Sam Ravnborg				     box_y, box_x + ITEM_IDENT + 1, menu_height);
353b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
354b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			wnoutrefresh(dialog);
355b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			wrefresh(menu);
356b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
357b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			continue;	/* wait for another key press */
358b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		}
359b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
360b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		switch (key) {
361b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case KEY_LEFT:
362b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case TAB:
363b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case KEY_RIGHT:
364b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			button = ((key == KEY_LEFT ? --button : ++button) < 0)
365b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			    ? 2 : (button > 2 ? 0 : button);
366b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
367b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			print_buttons(dialog, height, width, button);
368b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			wrefresh(menu);
369b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			break;
370b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case ' ':
371b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case 's':
372b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case 'y':
373b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case 'n':
374b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case 'm':
375b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case '/':
376b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			/* save scroll info */
377b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) {
378b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				fprintf(f, "%d\n", scroll);
379b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				fclose(f);
380b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			}
381b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			delwin(dialog);
382b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			fprintf(stderr, "%s\n", items[(scroll + choice) * 2]);
383b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			switch (key) {
384b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			case 's':
385b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				return 3;
386b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			case 'y':
387b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				return 3;
388b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			case 'n':
389b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				return 4;
390b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			case 'm':
391b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				return 5;
392b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			case ' ':
393b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				return 6;
394b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			case '/':
395b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				return 7;
396b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			}
397b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			return 0;
398b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case 'h':
399b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case '?':
400b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			button = 2;
401b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case '\n':
402b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			delwin(dialog);
403b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			if (button == 2)
404b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				fprintf(stderr, "%s \"%s\"\n",
405b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					items[(scroll + choice) * 2],
406b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					items[(scroll + choice) * 2 + 1] +
407dec69da856653772d7ee7b2f98dc69da27274a22Sam Ravnborg					first_alpha(items [(scroll + choice) * 2 + 1], ""));
408b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			else
409b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg				fprintf(stderr, "%s\n",
410b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg					items[(scroll + choice) * 2]);
411b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg
412b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			remove("lxdialog.scrltmp");
413b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			return button;
414b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case 'e':
415b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case 'x':
416b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			key = ESC;
417b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		case ESC:
418b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg			break;
419b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg		}
4201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
4211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
422b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	delwin(dialog);
423b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	remove("lxdialog.scrltmp");
424b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2Sam Ravnborg	return -1;		/* ESC pressed */
4251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
426