]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - scripts/kconfig/lxdialog/inputbox.c
2 * inputbox.c -- implements the input box
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 char dialog_input_result
[MAX_LEN
+ 1];
27 * Print the termination buttons
29 static void print_buttons(WINDOW
* dialog
, int height
, int width
, int selected
)
31 int x
= width
/ 2 - 11;
34 print_button(dialog
, gettext(" Ok "), y
, x
, selected
== 0);
35 print_button(dialog
, gettext(" Help "), y
, x
+ 14, selected
== 1);
37 wmove(dialog
, y
, x
+ 1 + 14 * selected
);
42 * Display a dialog box for inputing a string
44 int dialog_inputbox(const char *title
, const char *prompt
, int height
, int width
,
47 int i
, x
, y
, box_y
, box_x
, box_width
;
48 int input_x
= 0, key
= 0, button
= -1;
50 char *instr
= dialog_input_result
;
59 if (getmaxy(stdscr
) <= (height
- INPUTBOX_HEIGTH_MIN
))
60 return -ERRDISPLAYTOOSMALL
;
61 if (getmaxx(stdscr
) <= (width
- INPUTBOX_WIDTH_MIN
))
62 return -ERRDISPLAYTOOSMALL
;
64 /* center dialog box on screen */
65 x
= (getmaxx(stdscr
) - width
) / 2;
66 y
= (getmaxy(stdscr
) - height
) / 2;
68 draw_shadow(stdscr
, y
, x
, height
, width
);
70 dialog
= newwin(height
, width
, y
, x
);
73 draw_box(dialog
, 0, 0, height
, width
,
74 dlg
.dialog
.atr
, dlg
.border
.atr
);
75 wattrset(dialog
, dlg
.border
.atr
);
76 mvwaddch(dialog
, height
- 3, 0, ACS_LTEE
);
77 for (i
= 0; i
< width
- 2; i
++)
78 waddch(dialog
, ACS_HLINE
);
79 wattrset(dialog
, dlg
.dialog
.atr
);
80 waddch(dialog
, ACS_RTEE
);
82 print_title(dialog
, title
, width
);
84 wattrset(dialog
, dlg
.dialog
.atr
);
85 print_autowrap(dialog
, prompt
, width
- 2, 1, 3);
87 /* Draw the input field box */
88 box_width
= width
- 6;
91 box_x
= (width
- box_width
) / 2;
92 draw_box(dialog
, y
+ 1, box_x
- 1, 3, box_width
+ 2,
93 dlg
.dialog
.atr
, dlg
.border
.atr
);
95 print_buttons(dialog
, height
, width
, 0);
97 /* Set up the initial value */
98 wmove(dialog
, box_y
, box_x
);
99 wattrset(dialog
, dlg
.inputbox
.atr
);
104 if (len
>= box_width
) {
105 show_x
= len
- box_width
+ 1;
106 input_x
= box_width
- 1;
107 for (i
= 0; i
< box_width
- 1; i
++)
108 waddch(dialog
, instr
[show_x
+ i
]);
112 waddstr(dialog
, instr
);
115 wmove(dialog
, box_y
, box_x
+ input_x
);
119 while (key
!= KEY_ESC
) {
120 key
= wgetch(dialog
);
122 if (button
== -1) { /* Input box selected */
132 wattrset(dialog
, dlg
.inputbox
.atr
);
139 for (i
= pos
- 1; i
< len
; i
++) {
140 instr
[i
] = instr
[i
+1];
147 wmove(dialog
, box_y
, box_x
);
148 for (i
= 0; i
< box_width
; i
++) {
149 if (!instr
[show_x
+ i
]) {
153 waddch(dialog
, instr
[show_x
+ i
]);
155 wmove(dialog
, box_y
, input_x
+ box_x
);
162 wmove(dialog
, box_y
, --input_x
+ box_x
);
163 } else if (input_x
== 0) {
165 wmove(dialog
, box_y
, box_x
);
166 for (i
= 0; i
< box_width
; i
++) {
167 if (!instr
[show_x
+ i
]) {
171 waddch(dialog
, instr
[show_x
+ i
]);
173 wmove(dialog
, box_y
, box_x
);
180 if (input_x
< box_width
- 1) {
181 wmove(dialog
, box_y
, ++input_x
+ box_x
);
182 } else if (input_x
== box_width
- 1) {
184 wmove(dialog
, box_y
, box_x
);
185 for (i
= 0; i
< box_width
; i
++) {
186 if (!instr
[show_x
+ i
]) {
190 waddch(dialog
, instr
[show_x
+ i
]);
192 wmove(dialog
, box_y
, input_x
+ box_x
);
198 if (key
< 0x100 && isprint(key
)) {
200 wattrset(dialog
, dlg
.inputbox
.atr
);
202 for (i
= len
; i
> pos
; i
--)
203 instr
[i
] = instr
[i
-1];
212 if (input_x
== box_width
- 1) {
218 wmove(dialog
, box_y
, box_x
);
219 for (i
= 0; i
< box_width
; i
++) {
220 if (!instr
[show_x
+ i
]) {
224 waddch(dialog
, instr
[show_x
+ i
]);
226 wmove(dialog
, box_y
, input_x
+ box_x
);
229 flash(); /* Alarm user about overflow */
247 button
= 1; /* Indicates "Help" button is selected */
248 print_buttons(dialog
, height
, width
, 1);
251 button
= -1; /* Indicates input box is selected */
252 print_buttons(dialog
, height
, width
, 0);
253 wmove(dialog
, box_y
, box_x
+ input_x
);
257 button
= 0; /* Indicates "OK" button is selected */
258 print_buttons(dialog
, height
, width
, 0);
267 button
= 0; /* Indicates "OK" button is selected */
268 print_buttons(dialog
, height
, width
, 0);
271 button
= 1; /* Indicates "Help" button is selected */
272 print_buttons(dialog
, height
, width
, 1);
275 button
= -1; /* Indicates input box is selected */
276 print_buttons(dialog
, height
, width
, 0);
277 wmove(dialog
, box_y
, box_x
+ input_x
);
285 return (button
== -1 ? 0 : button
);
291 key
= on_key_esc(dialog
);
301 return KEY_ESC
; /* ESC pressed */