annotate kconfig/lxdialog/inputbox.c @ 847:2506cbdccd20

Partial cleanup of find - Remove unnecessary headers - dump_node is not used anywhere - exec_buf is unused - Replace SUCCESS with 1 and simplify code accordingly - a==0 -> !a - Simplify an incremation pattern using pre-increments - Add static keyword to functions - Make error messages print to stderr
author Felix Janda <felix.janda@posteo.de>
date Wed, 10 Apr 2013 19:25:06 +0200
parents 4d21d59f3206
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
1 /*
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
2 * inputbox.c -- implements the input box
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
3 *
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
6 *
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
9 * as published by the Free Software Foundation; either version 2
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
10 * of the License, or (at your option) any later version.
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
11 *
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
15 * GNU General Public License for more details.
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
16 *
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
20 */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
21
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
22 #include "dialog.h"
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
23
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
24 char dialog_input_result[MAX_LEN + 1];
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
25
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
26 /*
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
27 * Print the termination buttons
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
28 */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
29 static void print_buttons(WINDOW * dialog, int height, int width, int selected)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
30 {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
31 int x = width / 2 - 11;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
32 int y = height - 2;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
33
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
34 print_button(dialog, " Ok ", y, x, selected == 0);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
35 print_button(dialog, " Help ", y, x + 14, selected == 1);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
36
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
37 wmove(dialog, y, x + 1 + 14 * selected);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
38 wrefresh(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
39 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
40
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
41 /*
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
42 * Display a dialog box for inputing a string
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
43 */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
44 int dialog_inputbox(const char *title, const char *prompt, int height, int width,
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
45 const char *init)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
46 {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
47 int i, x, y, box_y, box_x, box_width;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
48 int input_x = 0, scroll = 0, key = 0, button = -1;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
49 char *instr = dialog_input_result;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
50 WINDOW *dialog;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
51
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
52 if (!init)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
53 instr[0] = '\0';
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
54 else
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
55 strcpy(instr, init);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
56
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
57 do_resize:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
58 if (getmaxy(stdscr) <= (height - 2))
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
59 return -ERRDISPLAYTOOSMALL;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
60 if (getmaxx(stdscr) <= (width - 2))
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
61 return -ERRDISPLAYTOOSMALL;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
62
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
63 /* center dialog box on screen */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
64 x = (COLS - width) / 2;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
65 y = (LINES - height) / 2;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
66
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
67 draw_shadow(stdscr, y, x, height, width);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
68
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
69 dialog = newwin(height, width, y, x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
70 keypad(dialog, TRUE);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
71
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
72 draw_box(dialog, 0, 0, height, width,
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
73 dlg.dialog.atr, dlg.border.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
74 wattrset(dialog, dlg.border.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
75 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
76 for (i = 0; i < width - 2; i++)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
77 waddch(dialog, ACS_HLINE);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
78 wattrset(dialog, dlg.dialog.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
79 waddch(dialog, ACS_RTEE);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
80
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
81 print_title(dialog, title, width);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
82
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
83 wattrset(dialog, dlg.dialog.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
84 print_autowrap(dialog, prompt, width - 2, 1, 3);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
85
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
86 /* Draw the input field box */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
87 box_width = width - 6;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
88 getyx(dialog, y, x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
89 box_y = y + 2;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
90 box_x = (width - box_width) / 2;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
91 draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
92 dlg.border.atr, dlg.dialog.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
93
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
94 print_buttons(dialog, height, width, 0);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
95
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
96 /* Set up the initial value */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
97 wmove(dialog, box_y, box_x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
98 wattrset(dialog, dlg.inputbox.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
99
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
100 input_x = strlen(instr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
101
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
102 if (input_x >= box_width) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
103 scroll = input_x - box_width + 1;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
104 input_x = box_width - 1;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
105 for (i = 0; i < box_width - 1; i++)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
106 waddch(dialog, instr[scroll + i]);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
107 } else {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
108 waddstr(dialog, instr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
109 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
110
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
111 wmove(dialog, box_y, box_x + input_x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
112
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
113 wrefresh(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
114
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
115 while (key != KEY_ESC) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
116 key = wgetch(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
117
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
118 if (button == -1) { /* Input box selected */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
119 switch (key) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
120 case TAB:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
121 case KEY_UP:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
122 case KEY_DOWN:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
123 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
124 case KEY_LEFT:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
125 continue;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
126 case KEY_RIGHT:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
127 continue;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
128 case KEY_BACKSPACE:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
129 case 127:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
130 if (input_x || scroll) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
131 wattrset(dialog, dlg.inputbox.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
132 if (!input_x) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
133 scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
134 wmove(dialog, box_y, box_x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
135 for (i = 0; i < box_width; i++)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
136 waddch(dialog,
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
137 instr[scroll + input_x + i] ?
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
138 instr[scroll + input_x + i] : ' ');
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
139 input_x = strlen(instr) - scroll;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
140 } else
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
141 input_x--;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
142 instr[scroll + input_x] = '\0';
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
143 mvwaddch(dialog, box_y, input_x + box_x, ' ');
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
144 wmove(dialog, box_y, input_x + box_x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
145 wrefresh(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
146 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
147 continue;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
148 default:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
149 if (key < 0x100 && isprint(key)) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
150 if (scroll + input_x < MAX_LEN) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
151 wattrset(dialog, dlg.inputbox.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
152 instr[scroll + input_x] = key;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
153 instr[scroll + input_x + 1] = '\0';
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
154 if (input_x == box_width - 1) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
155 scroll++;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
156 wmove(dialog, box_y, box_x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
157 for (i = 0; i < box_width - 1; i++)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
158 waddch(dialog, instr [scroll + i]);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
159 } else {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
160 wmove(dialog, box_y, input_x++ + box_x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
161 waddch(dialog, key);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
162 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
163 wrefresh(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
164 } else
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
165 flash(); /* Alarm user about overflow */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
166 continue;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
167 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
168 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
169 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
170 switch (key) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
171 case 'O':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
172 case 'o':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
173 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
174 return 0;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
175 case 'H':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
176 case 'h':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
177 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
178 return 1;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
179 case KEY_UP:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
180 case KEY_LEFT:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
181 switch (button) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
182 case -1:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
183 button = 1; /* Indicates "Cancel" button is selected */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
184 print_buttons(dialog, height, width, 1);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
185 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
186 case 0:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
187 button = -1; /* Indicates input box is selected */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
188 print_buttons(dialog, height, width, 0);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
189 wmove(dialog, box_y, box_x + input_x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
190 wrefresh(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
191 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
192 case 1:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
193 button = 0; /* Indicates "OK" button is selected */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
194 print_buttons(dialog, height, width, 0);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
195 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
196 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
197 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
198 case TAB:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
199 case KEY_DOWN:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
200 case KEY_RIGHT:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
201 switch (button) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
202 case -1:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
203 button = 0; /* Indicates "OK" button is selected */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
204 print_buttons(dialog, height, width, 0);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
205 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
206 case 0:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
207 button = 1; /* Indicates "Cancel" button is selected */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
208 print_buttons(dialog, height, width, 1);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
209 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
210 case 1:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
211 button = -1; /* Indicates input box is selected */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
212 print_buttons(dialog, height, width, 0);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
213 wmove(dialog, box_y, box_x + input_x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
214 wrefresh(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
215 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
216 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
217 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
218 case ' ':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
219 case '\n':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
220 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
221 return (button == -1 ? 0 : button);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
222 case 'X':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
223 case 'x':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
224 key = KEY_ESC;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
225 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
226 case KEY_ESC:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
227 key = on_key_esc(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
228 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
229 case KEY_RESIZE:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
230 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
231 on_key_resize();
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
232 goto do_resize;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
233 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
234 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
235
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
236 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
237 return KEY_ESC; /* ESC pressed */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
238 }