^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * inputbox.c -- implements the input box
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "dialog.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) char dialog_input_result[MAX_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Print the termination buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static void print_buttons(WINDOW * dialog, int height, int width, int selected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) int x = width / 2 - 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) int y = height - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) print_button(dialog, " Ok ", y, x, selected == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) print_button(dialog, " Help ", y, x + 14, selected == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) wmove(dialog, y, x + 1 + 14 * selected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) wrefresh(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Display a dialog box for inputing a string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int dialog_inputbox(const char *title, const char *prompt, int height, int width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) const char *init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int i, x, y, box_y, box_x, box_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int input_x = 0, key = 0, button = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int show_x, len, pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) char *instr = dialog_input_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) WINDOW *dialog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (!init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) instr[0] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) strcpy(instr, init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) do_resize:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (getmaxy(stdscr) <= (height - INPUTBOX_HEIGTH_MIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return -ERRDISPLAYTOOSMALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (getmaxx(stdscr) <= (width - INPUTBOX_WIDTH_MIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return -ERRDISPLAYTOOSMALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* center dialog box on screen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) x = (getmaxx(stdscr) - width) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) y = (getmaxy(stdscr) - height) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) draw_shadow(stdscr, y, x, height, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) dialog = newwin(height, width, y, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) keypad(dialog, TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) draw_box(dialog, 0, 0, height, width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) dlg.dialog.atr, dlg.border.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) wattrset(dialog, dlg.border.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) mvwaddch(dialog, height - 3, 0, ACS_LTEE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) for (i = 0; i < width - 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) waddch(dialog, ACS_HLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) wattrset(dialog, dlg.dialog.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) waddch(dialog, ACS_RTEE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) print_title(dialog, title, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) wattrset(dialog, dlg.dialog.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) print_autowrap(dialog, prompt, width - 2, 1, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* Draw the input field box */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) box_width = width - 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) getyx(dialog, y, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) box_y = y + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) box_x = (width - box_width) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) dlg.dialog.atr, dlg.border.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) print_buttons(dialog, height, width, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* Set up the initial value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) wmove(dialog, box_y, box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) wattrset(dialog, dlg.inputbox.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) len = strlen(instr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) pos = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (len >= box_width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) show_x = len - box_width + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) input_x = box_width - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) for (i = 0; i < box_width - 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) waddch(dialog, instr[show_x + i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) show_x = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) input_x = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) waddstr(dialog, instr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) wmove(dialog, box_y, box_x + input_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) wrefresh(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) while (key != KEY_ESC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) key = wgetch(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (button == -1) { /* Input box selected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) case TAB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) case KEY_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) case KEY_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case KEY_BACKSPACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) case 8: /* ^H */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) case 127: /* ^? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) wattrset(dialog, dlg.inputbox.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (input_x == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) show_x--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) input_x--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (pos < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) for (i = pos - 1; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) instr[i] = instr[i+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) pos--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) instr[len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) wmove(dialog, box_y, box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) for (i = 0; i < box_width; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (!instr[show_x + i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) waddch(dialog, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) waddch(dialog, instr[show_x + i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) wmove(dialog, box_y, input_x + box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) wrefresh(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) case KEY_LEFT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (pos > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (input_x > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) wmove(dialog, box_y, --input_x + box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) } else if (input_x == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) show_x--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) wmove(dialog, box_y, box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) for (i = 0; i < box_width; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (!instr[show_x + i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) waddch(dialog, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) waddch(dialog, instr[show_x + i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) wmove(dialog, box_y, box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) pos--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) case KEY_RIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (pos < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (input_x < box_width - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) wmove(dialog, box_y, ++input_x + box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) } else if (input_x == box_width - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) show_x++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) wmove(dialog, box_y, box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) for (i = 0; i < box_width; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!instr[show_x + i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) waddch(dialog, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) waddch(dialog, instr[show_x + i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) wmove(dialog, box_y, input_x + box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (key < 0x100 && isprint(key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (len < MAX_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) wattrset(dialog, dlg.inputbox.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (pos < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) for (i = len; i > pos; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) instr[i] = instr[i-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) instr[pos] = key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) instr[len] = key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) len++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) instr[len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (input_x == box_width - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) show_x++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) input_x++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) wmove(dialog, box_y, box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) for (i = 0; i < box_width; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (!instr[show_x + i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) waddch(dialog, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) waddch(dialog, instr[show_x + i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) wmove(dialog, box_y, input_x + box_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) wrefresh(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) flash(); /* Alarm user about overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) case 'O':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) case 'o':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) case 'H':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) case 'h':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) case KEY_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) case KEY_LEFT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) switch (button) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) case -1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) button = 1; /* Indicates "Help" button is selected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) print_buttons(dialog, height, width, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) button = -1; /* Indicates input box is selected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) print_buttons(dialog, height, width, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) wmove(dialog, box_y, box_x + input_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) wrefresh(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) button = 0; /* Indicates "OK" button is selected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) print_buttons(dialog, height, width, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) case TAB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) case KEY_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) case KEY_RIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) switch (button) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) case -1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) button = 0; /* Indicates "OK" button is selected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) print_buttons(dialog, height, width, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) button = 1; /* Indicates "Help" button is selected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) print_buttons(dialog, height, width, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) button = -1; /* Indicates input box is selected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) print_buttons(dialog, height, width, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) wmove(dialog, box_y, box_x + input_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) wrefresh(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) case ' ':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) case '\n':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return (button == -1 ? 0 : button);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) case 'X':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) case 'x':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) key = KEY_ESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) case KEY_ESC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) key = on_key_esc(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) case KEY_RESIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) on_key_resize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) goto do_resize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return KEY_ESC; /* ESC pressed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }