10f66f451Sopenharmony_ci/* 20f66f451Sopenharmony_ci * menubox.c -- implements the menu box 30f66f451Sopenharmony_ci * 40f66f451Sopenharmony_ci * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) 50f66f451Sopenharmony_ci * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com) 60f66f451Sopenharmony_ci * 70f66f451Sopenharmony_ci * This program is free software; you can redistribute it and/or 80f66f451Sopenharmony_ci * modify it under the terms of the GNU General Public License 90f66f451Sopenharmony_ci * as published by the Free Software Foundation; either version 2 100f66f451Sopenharmony_ci * of the License, or (at your option) any later version. 110f66f451Sopenharmony_ci * 120f66f451Sopenharmony_ci * This program is distributed in the hope that it will be useful, 130f66f451Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 140f66f451Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 150f66f451Sopenharmony_ci * GNU General Public License for more details. 160f66f451Sopenharmony_ci * 170f66f451Sopenharmony_ci * You should have received a copy of the GNU General Public License 180f66f451Sopenharmony_ci * along with this program; if not, write to the Free Software 190f66f451Sopenharmony_ci * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 200f66f451Sopenharmony_ci */ 210f66f451Sopenharmony_ci 220f66f451Sopenharmony_ci/* 230f66f451Sopenharmony_ci * Changes by Clifford Wolf (god@clifford.at) 240f66f451Sopenharmony_ci * 250f66f451Sopenharmony_ci * [ 1998-06-13 ] 260f66f451Sopenharmony_ci * 270f66f451Sopenharmony_ci * *) A bugfix for the Page-Down problem 280f66f451Sopenharmony_ci * 290f66f451Sopenharmony_ci * *) Formerly when I used Page Down and Page Up, the cursor would be set 300f66f451Sopenharmony_ci * to the first position in the menu box. Now lxdialog is a bit 310f66f451Sopenharmony_ci * smarter and works more like other menu systems (just have a look at 320f66f451Sopenharmony_ci * it). 330f66f451Sopenharmony_ci * 340f66f451Sopenharmony_ci * *) Formerly if I selected something my scrolling would be broken because 350f66f451Sopenharmony_ci * lxdialog is re-invoked by the Menuconfig shell script, can't 360f66f451Sopenharmony_ci * remember the last scrolling position, and just sets it so that the 370f66f451Sopenharmony_ci * cursor is at the bottom of the box. Now it writes the temporary file 380f66f451Sopenharmony_ci * lxdialog.scrltmp which contains this information. The file is 390f66f451Sopenharmony_ci * deleted by lxdialog if the user leaves a submenu or enters a new 400f66f451Sopenharmony_ci * one, but it would be nice if Menuconfig could make another "rm -f" 410f66f451Sopenharmony_ci * just to be sure. Just try it out - you will recognise a difference! 420f66f451Sopenharmony_ci * 430f66f451Sopenharmony_ci * [ 1998-06-14 ] 440f66f451Sopenharmony_ci * 450f66f451Sopenharmony_ci * *) Now lxdialog is crash-safe against broken "lxdialog.scrltmp" files 460f66f451Sopenharmony_ci * and menus change their size on the fly. 470f66f451Sopenharmony_ci * 480f66f451Sopenharmony_ci * *) If for some reason the last scrolling position is not saved by 490f66f451Sopenharmony_ci * lxdialog, it sets the scrolling so that the selected item is in the 500f66f451Sopenharmony_ci * middle of the menu box, not at the bottom. 510f66f451Sopenharmony_ci * 520f66f451Sopenharmony_ci * 02 January 1999, Michael Elizabeth Chastain (mec@shout.net) 530f66f451Sopenharmony_ci * Reset 'scroll' to 0 if the value from lxdialog.scrltmp is bogus. 540f66f451Sopenharmony_ci * This fixes a bug in Menuconfig where using ' ' to descend into menus 550f66f451Sopenharmony_ci * would leave mis-synchronized lxdialog.scrltmp files lying around, 560f66f451Sopenharmony_ci * fscanf would read in 'scroll', and eventually that value would get used. 570f66f451Sopenharmony_ci */ 580f66f451Sopenharmony_ci 590f66f451Sopenharmony_ci#include "dialog.h" 600f66f451Sopenharmony_ci 610f66f451Sopenharmony_cistatic int menu_width, item_x; 620f66f451Sopenharmony_ci 630f66f451Sopenharmony_ci/* 640f66f451Sopenharmony_ci * Print menu item 650f66f451Sopenharmony_ci */ 660f66f451Sopenharmony_cistatic void do_print_item(WINDOW * win, const char *item, int line_y, 670f66f451Sopenharmony_ci int selected, int hotkey) 680f66f451Sopenharmony_ci{ 690f66f451Sopenharmony_ci int j; 700f66f451Sopenharmony_ci char *menu_item = malloc(menu_width + 1); 710f66f451Sopenharmony_ci 720f66f451Sopenharmony_ci strncpy(menu_item, item, menu_width - item_x); 730f66f451Sopenharmony_ci menu_item[menu_width - item_x] = '\0'; 740f66f451Sopenharmony_ci j = first_alpha(menu_item, "YyNnMmHh"); 750f66f451Sopenharmony_ci 760f66f451Sopenharmony_ci /* Clear 'residue' of last item */ 770f66f451Sopenharmony_ci wattrset(win, dlg.menubox.atr); 780f66f451Sopenharmony_ci wmove(win, line_y, 0); 790f66f451Sopenharmony_ci#if OLD_NCURSES 800f66f451Sopenharmony_ci { 810f66f451Sopenharmony_ci int i; 820f66f451Sopenharmony_ci for (i = 0; i < menu_width; i++) 830f66f451Sopenharmony_ci waddch(win, ' '); 840f66f451Sopenharmony_ci } 850f66f451Sopenharmony_ci#else 860f66f451Sopenharmony_ci wclrtoeol(win); 870f66f451Sopenharmony_ci#endif 880f66f451Sopenharmony_ci wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); 890f66f451Sopenharmony_ci mvwaddstr(win, line_y, item_x, menu_item); 900f66f451Sopenharmony_ci if (hotkey) { 910f66f451Sopenharmony_ci wattrset(win, selected ? dlg.tag_key_selected.atr 920f66f451Sopenharmony_ci : dlg.tag_key.atr); 930f66f451Sopenharmony_ci mvwaddch(win, line_y, item_x + j, menu_item[j]); 940f66f451Sopenharmony_ci } 950f66f451Sopenharmony_ci if (selected) { 960f66f451Sopenharmony_ci wmove(win, line_y, item_x + 1); 970f66f451Sopenharmony_ci } 980f66f451Sopenharmony_ci free(menu_item); 990f66f451Sopenharmony_ci wrefresh(win); 1000f66f451Sopenharmony_ci} 1010f66f451Sopenharmony_ci 1020f66f451Sopenharmony_ci#define print_item(index, choice, selected) \ 1030f66f451Sopenharmony_cido { \ 1040f66f451Sopenharmony_ci item_set(index); \ 1050f66f451Sopenharmony_ci do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \ 1060f66f451Sopenharmony_ci} while (0) 1070f66f451Sopenharmony_ci 1080f66f451Sopenharmony_ci/* 1090f66f451Sopenharmony_ci * Print the scroll indicators. 1100f66f451Sopenharmony_ci */ 1110f66f451Sopenharmony_cistatic void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, 1120f66f451Sopenharmony_ci int height) 1130f66f451Sopenharmony_ci{ 1140f66f451Sopenharmony_ci int cur_y, cur_x; 1150f66f451Sopenharmony_ci 1160f66f451Sopenharmony_ci getyx(win, cur_y, cur_x); 1170f66f451Sopenharmony_ci 1180f66f451Sopenharmony_ci wmove(win, y, x); 1190f66f451Sopenharmony_ci 1200f66f451Sopenharmony_ci if (scroll > 0) { 1210f66f451Sopenharmony_ci wattrset(win, dlg.uarrow.atr); 1220f66f451Sopenharmony_ci waddch(win, ACS_UARROW); 1230f66f451Sopenharmony_ci waddstr(win, "(-)"); 1240f66f451Sopenharmony_ci } else { 1250f66f451Sopenharmony_ci wattrset(win, dlg.menubox.atr); 1260f66f451Sopenharmony_ci waddch(win, ACS_HLINE); 1270f66f451Sopenharmony_ci waddch(win, ACS_HLINE); 1280f66f451Sopenharmony_ci waddch(win, ACS_HLINE); 1290f66f451Sopenharmony_ci waddch(win, ACS_HLINE); 1300f66f451Sopenharmony_ci } 1310f66f451Sopenharmony_ci 1320f66f451Sopenharmony_ci y = y + height + 1; 1330f66f451Sopenharmony_ci wmove(win, y, x); 1340f66f451Sopenharmony_ci wrefresh(win); 1350f66f451Sopenharmony_ci 1360f66f451Sopenharmony_ci if ((height < item_no) && (scroll + height < item_no)) { 1370f66f451Sopenharmony_ci wattrset(win, dlg.darrow.atr); 1380f66f451Sopenharmony_ci waddch(win, ACS_DARROW); 1390f66f451Sopenharmony_ci waddstr(win, "(+)"); 1400f66f451Sopenharmony_ci } else { 1410f66f451Sopenharmony_ci wattrset(win, dlg.menubox_border.atr); 1420f66f451Sopenharmony_ci waddch(win, ACS_HLINE); 1430f66f451Sopenharmony_ci waddch(win, ACS_HLINE); 1440f66f451Sopenharmony_ci waddch(win, ACS_HLINE); 1450f66f451Sopenharmony_ci waddch(win, ACS_HLINE); 1460f66f451Sopenharmony_ci } 1470f66f451Sopenharmony_ci 1480f66f451Sopenharmony_ci wmove(win, cur_y, cur_x); 1490f66f451Sopenharmony_ci wrefresh(win); 1500f66f451Sopenharmony_ci} 1510f66f451Sopenharmony_ci 1520f66f451Sopenharmony_ci/* 1530f66f451Sopenharmony_ci * Display the termination buttons. 1540f66f451Sopenharmony_ci */ 1550f66f451Sopenharmony_cistatic void print_buttons(WINDOW * win, int height, int width, int selected) 1560f66f451Sopenharmony_ci{ 1570f66f451Sopenharmony_ci int x = width / 2 - 16; 1580f66f451Sopenharmony_ci int y = height - 2; 1590f66f451Sopenharmony_ci 1600f66f451Sopenharmony_ci print_button(win, "Select", y, x, selected == 0); 1610f66f451Sopenharmony_ci print_button(win, " Exit ", y, x + 12, selected == 1); 1620f66f451Sopenharmony_ci print_button(win, " Help ", y, x + 24, selected == 2); 1630f66f451Sopenharmony_ci 1640f66f451Sopenharmony_ci wmove(win, y, x + 1 + 12 * selected); 1650f66f451Sopenharmony_ci wrefresh(win); 1660f66f451Sopenharmony_ci} 1670f66f451Sopenharmony_ci 1680f66f451Sopenharmony_ci/* scroll up n lines (n may be negative) */ 1690f66f451Sopenharmony_cistatic void do_scroll(WINDOW *win, int *scroll, int n) 1700f66f451Sopenharmony_ci{ 1710f66f451Sopenharmony_ci /* Scroll menu up */ 1720f66f451Sopenharmony_ci scrollok(win, TRUE); 1730f66f451Sopenharmony_ci wscrl(win, n); 1740f66f451Sopenharmony_ci scrollok(win, FALSE); 1750f66f451Sopenharmony_ci *scroll = *scroll + n; 1760f66f451Sopenharmony_ci wrefresh(win); 1770f66f451Sopenharmony_ci} 1780f66f451Sopenharmony_ci 1790f66f451Sopenharmony_ci/* 1800f66f451Sopenharmony_ci * Display a menu for choosing among a number of options 1810f66f451Sopenharmony_ci */ 1820f66f451Sopenharmony_ciint dialog_menu(const char *title, const char *prompt, 1830f66f451Sopenharmony_ci const void *selected, int *s_scroll) 1840f66f451Sopenharmony_ci{ 1850f66f451Sopenharmony_ci int i, j, x, y, box_x, box_y; 1860f66f451Sopenharmony_ci int height, width, menu_height; 1870f66f451Sopenharmony_ci int key = 0, button = 0, scroll = 0, choice = 0; 1880f66f451Sopenharmony_ci int first_item = 0, max_choice; 1890f66f451Sopenharmony_ci WINDOW *dialog, *menu; 1900f66f451Sopenharmony_ci 1910f66f451Sopenharmony_cido_resize: 1920f66f451Sopenharmony_ci height = getmaxy(stdscr); 1930f66f451Sopenharmony_ci width = getmaxx(stdscr); 1940f66f451Sopenharmony_ci if (height < 15 || width < 65) 1950f66f451Sopenharmony_ci return -ERRDISPLAYTOOSMALL; 1960f66f451Sopenharmony_ci 1970f66f451Sopenharmony_ci height -= 4; 1980f66f451Sopenharmony_ci width -= 5; 1990f66f451Sopenharmony_ci menu_height = height - 10; 2000f66f451Sopenharmony_ci 2010f66f451Sopenharmony_ci max_choice = MIN(menu_height, item_count()); 2020f66f451Sopenharmony_ci 2030f66f451Sopenharmony_ci /* center dialog box on screen */ 2040f66f451Sopenharmony_ci x = (COLS - width) / 2; 2050f66f451Sopenharmony_ci y = (LINES - height) / 2; 2060f66f451Sopenharmony_ci 2070f66f451Sopenharmony_ci draw_shadow(stdscr, y, x, height, width); 2080f66f451Sopenharmony_ci 2090f66f451Sopenharmony_ci dialog = newwin(height, width, y, x); 2100f66f451Sopenharmony_ci keypad(dialog, TRUE); 2110f66f451Sopenharmony_ci 2120f66f451Sopenharmony_ci draw_box(dialog, 0, 0, height, width, 2130f66f451Sopenharmony_ci dlg.dialog.atr, dlg.border.atr); 2140f66f451Sopenharmony_ci wattrset(dialog, dlg.border.atr); 2150f66f451Sopenharmony_ci mvwaddch(dialog, height - 3, 0, ACS_LTEE); 2160f66f451Sopenharmony_ci for (i = 0; i < width - 2; i++) 2170f66f451Sopenharmony_ci waddch(dialog, ACS_HLINE); 2180f66f451Sopenharmony_ci wattrset(dialog, dlg.dialog.atr); 2190f66f451Sopenharmony_ci wbkgdset(dialog, dlg.dialog.atr & A_COLOR); 2200f66f451Sopenharmony_ci waddch(dialog, ACS_RTEE); 2210f66f451Sopenharmony_ci 2220f66f451Sopenharmony_ci print_title(dialog, title, width); 2230f66f451Sopenharmony_ci 2240f66f451Sopenharmony_ci wattrset(dialog, dlg.dialog.atr); 2250f66f451Sopenharmony_ci print_autowrap(dialog, prompt, width - 2, 1, 3); 2260f66f451Sopenharmony_ci 2270f66f451Sopenharmony_ci menu_width = width - 6; 2280f66f451Sopenharmony_ci box_y = height - menu_height - 5; 2290f66f451Sopenharmony_ci box_x = (width - menu_width) / 2 - 1; 2300f66f451Sopenharmony_ci 2310f66f451Sopenharmony_ci /* create new window for the menu */ 2320f66f451Sopenharmony_ci menu = subwin(dialog, menu_height, menu_width, 2330f66f451Sopenharmony_ci y + box_y + 1, x + box_x + 1); 2340f66f451Sopenharmony_ci keypad(menu, TRUE); 2350f66f451Sopenharmony_ci 2360f66f451Sopenharmony_ci /* draw a box around the menu items */ 2370f66f451Sopenharmony_ci draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, 2380f66f451Sopenharmony_ci dlg.menubox_border.atr, dlg.menubox.atr); 2390f66f451Sopenharmony_ci 2400f66f451Sopenharmony_ci if (menu_width >= 80) 2410f66f451Sopenharmony_ci item_x = (menu_width - 70) / 2; 2420f66f451Sopenharmony_ci else 2430f66f451Sopenharmony_ci item_x = 4; 2440f66f451Sopenharmony_ci 2450f66f451Sopenharmony_ci /* Set choice to default item */ 2460f66f451Sopenharmony_ci item_foreach() 2470f66f451Sopenharmony_ci if (selected && (selected == item_data())) 2480f66f451Sopenharmony_ci choice = item_n(); 2490f66f451Sopenharmony_ci /* get the saved scroll info */ 2500f66f451Sopenharmony_ci scroll = *s_scroll; 2510f66f451Sopenharmony_ci if ((scroll <= choice) && (scroll + max_choice > choice) && 2520f66f451Sopenharmony_ci (scroll >= 0) && (scroll + max_choice <= item_count())) { 2530f66f451Sopenharmony_ci first_item = scroll; 2540f66f451Sopenharmony_ci choice = choice - scroll; 2550f66f451Sopenharmony_ci } else { 2560f66f451Sopenharmony_ci scroll = 0; 2570f66f451Sopenharmony_ci } 2580f66f451Sopenharmony_ci if ((choice >= max_choice)) { 2590f66f451Sopenharmony_ci if (choice >= item_count() - max_choice / 2) 2600f66f451Sopenharmony_ci scroll = first_item = item_count() - max_choice; 2610f66f451Sopenharmony_ci else 2620f66f451Sopenharmony_ci scroll = first_item = choice - max_choice / 2; 2630f66f451Sopenharmony_ci choice = choice - scroll; 2640f66f451Sopenharmony_ci } 2650f66f451Sopenharmony_ci 2660f66f451Sopenharmony_ci /* Print the menu */ 2670f66f451Sopenharmony_ci for (i = 0; i < max_choice; i++) { 2680f66f451Sopenharmony_ci print_item(first_item + i, i, i == choice); 2690f66f451Sopenharmony_ci } 2700f66f451Sopenharmony_ci 2710f66f451Sopenharmony_ci wnoutrefresh(menu); 2720f66f451Sopenharmony_ci 2730f66f451Sopenharmony_ci print_arrows(dialog, item_count(), scroll, 2740f66f451Sopenharmony_ci box_y, box_x + item_x + 1, menu_height); 2750f66f451Sopenharmony_ci 2760f66f451Sopenharmony_ci print_buttons(dialog, height, width, 0); 2770f66f451Sopenharmony_ci wmove(menu, choice, item_x + 1); 2780f66f451Sopenharmony_ci wrefresh(menu); 2790f66f451Sopenharmony_ci 2800f66f451Sopenharmony_ci while (key != KEY_ESC) { 2810f66f451Sopenharmony_ci key = wgetch(menu); 2820f66f451Sopenharmony_ci 2830f66f451Sopenharmony_ci if (key < 256 && isalpha(key)) 2840f66f451Sopenharmony_ci key = tolower(key); 2850f66f451Sopenharmony_ci 2860f66f451Sopenharmony_ci if (strchr("ynmh", key)) 2870f66f451Sopenharmony_ci i = max_choice; 2880f66f451Sopenharmony_ci else { 2890f66f451Sopenharmony_ci for (i = choice + 1; i < max_choice; i++) { 2900f66f451Sopenharmony_ci item_set(scroll + i); 2910f66f451Sopenharmony_ci j = first_alpha(item_str(), "YyNnMmHh"); 2920f66f451Sopenharmony_ci if (key == tolower(item_str()[j])) 2930f66f451Sopenharmony_ci break; 2940f66f451Sopenharmony_ci } 2950f66f451Sopenharmony_ci if (i == max_choice) 2960f66f451Sopenharmony_ci for (i = 0; i < max_choice; i++) { 2970f66f451Sopenharmony_ci item_set(scroll + i); 2980f66f451Sopenharmony_ci j = first_alpha(item_str(), "YyNnMmHh"); 2990f66f451Sopenharmony_ci if (key == tolower(item_str()[j])) 3000f66f451Sopenharmony_ci break; 3010f66f451Sopenharmony_ci } 3020f66f451Sopenharmony_ci } 3030f66f451Sopenharmony_ci 3040f66f451Sopenharmony_ci if (i < max_choice || 3050f66f451Sopenharmony_ci key == KEY_UP || key == KEY_DOWN || 3060f66f451Sopenharmony_ci key == '-' || key == '+' || 3070f66f451Sopenharmony_ci key == KEY_PPAGE || key == KEY_NPAGE) { 3080f66f451Sopenharmony_ci /* Remove highligt of current item */ 3090f66f451Sopenharmony_ci print_item(scroll + choice, choice, FALSE); 3100f66f451Sopenharmony_ci 3110f66f451Sopenharmony_ci if (key == KEY_UP || key == '-') { 3120f66f451Sopenharmony_ci if (choice < 2 && scroll) { 3130f66f451Sopenharmony_ci /* Scroll menu down */ 3140f66f451Sopenharmony_ci do_scroll(menu, &scroll, -1); 3150f66f451Sopenharmony_ci 3160f66f451Sopenharmony_ci print_item(scroll, 0, FALSE); 3170f66f451Sopenharmony_ci } else 3180f66f451Sopenharmony_ci choice = MAX(choice - 1, 0); 3190f66f451Sopenharmony_ci 3200f66f451Sopenharmony_ci } else if (key == KEY_DOWN || key == '+') { 3210f66f451Sopenharmony_ci print_item(scroll+choice, choice, FALSE); 3220f66f451Sopenharmony_ci 3230f66f451Sopenharmony_ci if ((choice > max_choice - 3) && 3240f66f451Sopenharmony_ci (scroll + max_choice < item_count())) { 3250f66f451Sopenharmony_ci /* Scroll menu up */ 3260f66f451Sopenharmony_ci do_scroll(menu, &scroll, 1); 3270f66f451Sopenharmony_ci 3280f66f451Sopenharmony_ci print_item(scroll+max_choice - 1, 3290f66f451Sopenharmony_ci max_choice - 1, FALSE); 3300f66f451Sopenharmony_ci } else 3310f66f451Sopenharmony_ci choice = MIN(choice + 1, max_choice - 1); 3320f66f451Sopenharmony_ci 3330f66f451Sopenharmony_ci } else if (key == KEY_PPAGE) { 3340f66f451Sopenharmony_ci scrollok(menu, TRUE); 3350f66f451Sopenharmony_ci for (i = 0; (i < max_choice); i++) { 3360f66f451Sopenharmony_ci if (scroll > 0) { 3370f66f451Sopenharmony_ci do_scroll(menu, &scroll, -1); 3380f66f451Sopenharmony_ci print_item(scroll, 0, FALSE); 3390f66f451Sopenharmony_ci } else { 3400f66f451Sopenharmony_ci if (choice > 0) 3410f66f451Sopenharmony_ci choice--; 3420f66f451Sopenharmony_ci } 3430f66f451Sopenharmony_ci } 3440f66f451Sopenharmony_ci 3450f66f451Sopenharmony_ci } else if (key == KEY_NPAGE) { 3460f66f451Sopenharmony_ci for (i = 0; (i < max_choice); i++) { 3470f66f451Sopenharmony_ci if (scroll + max_choice < item_count()) { 3480f66f451Sopenharmony_ci do_scroll(menu, &scroll, 1); 3490f66f451Sopenharmony_ci print_item(scroll+max_choice-1, 3500f66f451Sopenharmony_ci max_choice - 1, FALSE); 3510f66f451Sopenharmony_ci } else { 3520f66f451Sopenharmony_ci if (choice + 1 < max_choice) 3530f66f451Sopenharmony_ci choice++; 3540f66f451Sopenharmony_ci } 3550f66f451Sopenharmony_ci } 3560f66f451Sopenharmony_ci } else 3570f66f451Sopenharmony_ci choice = i; 3580f66f451Sopenharmony_ci 3590f66f451Sopenharmony_ci print_item(scroll + choice, choice, TRUE); 3600f66f451Sopenharmony_ci 3610f66f451Sopenharmony_ci print_arrows(dialog, item_count(), scroll, 3620f66f451Sopenharmony_ci box_y, box_x + item_x + 1, menu_height); 3630f66f451Sopenharmony_ci 3640f66f451Sopenharmony_ci wnoutrefresh(dialog); 3650f66f451Sopenharmony_ci wrefresh(menu); 3660f66f451Sopenharmony_ci 3670f66f451Sopenharmony_ci continue; /* wait for another key press */ 3680f66f451Sopenharmony_ci } 3690f66f451Sopenharmony_ci 3700f66f451Sopenharmony_ci switch (key) { 3710f66f451Sopenharmony_ci case KEY_LEFT: 3720f66f451Sopenharmony_ci case TAB: 3730f66f451Sopenharmony_ci case KEY_RIGHT: 3740f66f451Sopenharmony_ci button = ((key == KEY_LEFT ? --button : ++button) < 0) 3750f66f451Sopenharmony_ci ? 2 : (button > 2 ? 0 : button); 3760f66f451Sopenharmony_ci 3770f66f451Sopenharmony_ci print_buttons(dialog, height, width, button); 3780f66f451Sopenharmony_ci wrefresh(menu); 3790f66f451Sopenharmony_ci break; 3800f66f451Sopenharmony_ci case ' ': 3810f66f451Sopenharmony_ci case 's': 3820f66f451Sopenharmony_ci case 'y': 3830f66f451Sopenharmony_ci case 'n': 3840f66f451Sopenharmony_ci case 'm': 3850f66f451Sopenharmony_ci case '/': 3860f66f451Sopenharmony_ci /* save scroll info */ 3870f66f451Sopenharmony_ci *s_scroll = scroll; 3880f66f451Sopenharmony_ci delwin(menu); 3890f66f451Sopenharmony_ci delwin(dialog); 3900f66f451Sopenharmony_ci item_set(scroll + choice); 3910f66f451Sopenharmony_ci item_set_selected(1); 3920f66f451Sopenharmony_ci switch (key) { 3930f66f451Sopenharmony_ci case 's': 3940f66f451Sopenharmony_ci return 3; 3950f66f451Sopenharmony_ci case 'y': 3960f66f451Sopenharmony_ci return 3; 3970f66f451Sopenharmony_ci case 'n': 3980f66f451Sopenharmony_ci return 4; 3990f66f451Sopenharmony_ci case 'm': 4000f66f451Sopenharmony_ci return 5; 4010f66f451Sopenharmony_ci case ' ': 4020f66f451Sopenharmony_ci return 6; 4030f66f451Sopenharmony_ci case '/': 4040f66f451Sopenharmony_ci return 7; 4050f66f451Sopenharmony_ci } 4060f66f451Sopenharmony_ci return 0; 4070f66f451Sopenharmony_ci case 'h': 4080f66f451Sopenharmony_ci case '?': 4090f66f451Sopenharmony_ci button = 2; 4100f66f451Sopenharmony_ci case '\n': 4110f66f451Sopenharmony_ci *s_scroll = scroll; 4120f66f451Sopenharmony_ci delwin(menu); 4130f66f451Sopenharmony_ci delwin(dialog); 4140f66f451Sopenharmony_ci item_set(scroll + choice); 4150f66f451Sopenharmony_ci item_set_selected(1); 4160f66f451Sopenharmony_ci return button; 4170f66f451Sopenharmony_ci case 'e': 4180f66f451Sopenharmony_ci case 'x': 4190f66f451Sopenharmony_ci key = KEY_ESC; 4200f66f451Sopenharmony_ci break; 4210f66f451Sopenharmony_ci case KEY_ESC: 4220f66f451Sopenharmony_ci key = on_key_esc(menu); 4230f66f451Sopenharmony_ci break; 4240f66f451Sopenharmony_ci case KEY_RESIZE: 4250f66f451Sopenharmony_ci on_key_resize(); 4260f66f451Sopenharmony_ci delwin(menu); 4270f66f451Sopenharmony_ci delwin(dialog); 4280f66f451Sopenharmony_ci goto do_resize; 4290f66f451Sopenharmony_ci } 4300f66f451Sopenharmony_ci } 4310f66f451Sopenharmony_ci delwin(menu); 4320f66f451Sopenharmony_ci delwin(dialog); 4330f66f451Sopenharmony_ci return key; /* ESC pressed */ 4340f66f451Sopenharmony_ci} 435