aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lxdialog/inputbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lxdialog/inputbox.c')
-rw-r--r--scripts/lxdialog/inputbox.c49
1 files changed, 15 insertions, 34 deletions
diff --git a/scripts/lxdialog/inputbox.c b/scripts/lxdialog/inputbox.c
index 9e9691567269..bc135c7093d9 100644
--- a/scripts/lxdialog/inputbox.c
+++ b/scripts/lxdialog/inputbox.c
@@ -41,9 +41,8 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)
41/* 41/*
42 * Display a dialog box for inputing a string 42 * Display a dialog box for inputing a string
43 */ 43 */
44int 44int dialog_inputbox(const char *title, const char *prompt, int height, int width,
45dialog_inputbox(const char *title, const char *prompt, int height, int width, 45 const char *init)
46 const char *init)
47{ 46{
48 int i, x, y, box_y, box_x, box_width; 47 int i, x, y, box_y, box_x, box_width;
49 int input_x = 0, scroll = 0, key = 0, button = -1; 48 int input_x = 0, scroll = 0, key = 0, button = -1;
@@ -90,8 +89,7 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
90 getyx(dialog, y, x); 89 getyx(dialog, y, x);
91 box_y = y + 2; 90 box_y = y + 2;
92 box_x = (width - box_width) / 2; 91 box_x = (width - box_width) / 2;
93 draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, 92 draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, border_attr, dialog_attr);
94 border_attr, dialog_attr);
95 93
96 print_buttons(dialog, height, width, 0); 94 print_buttons(dialog, height, width, 0);
97 95
@@ -111,8 +109,9 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
111 input_x = box_width - 1; 109 input_x = box_width - 1;
112 for (i = 0; i < box_width - 1; i++) 110 for (i = 0; i < box_width - 1; i++)
113 waddch(dialog, instr[scroll + i]); 111 waddch(dialog, instr[scroll + i]);
114 } else 112 } else {
115 waddstr(dialog, instr); 113 waddstr(dialog, instr);
114 }
116 115
117 wmove(dialog, box_y, box_x + input_x); 116 wmove(dialog, box_y, box_x + input_x);
118 117
@@ -136,26 +135,17 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
136 if (input_x || scroll) { 135 if (input_x || scroll) {
137 wattrset(dialog, inputbox_attr); 136 wattrset(dialog, inputbox_attr);
138 if (!input_x) { 137 if (!input_x) {
139 scroll = 138 scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
140 scroll <
141 box_width - 1 ? 0 : scroll -
142 (box_width - 1);
143 wmove(dialog, box_y, box_x); 139 wmove(dialog, box_y, box_x);
144 for (i = 0; i < box_width; i++) 140 for (i = 0; i < box_width; i++)
145 waddch(dialog, 141 waddch(dialog,
146 instr[scroll + 142 instr[scroll + input_x + i] ?
147 input_x + 143 instr[scroll + input_x + i] : ' ');
148 i] ? 144 input_x = strlen(instr) - scroll;
149 instr[scroll +
150 input_x +
151 i] : ' ');
152 input_x =
153 strlen(instr) - scroll;
154 } else 145 } else
155 input_x--; 146 input_x--;
156 instr[scroll + input_x] = '\0'; 147 instr[scroll + input_x] = '\0';
157 mvwaddch(dialog, box_y, input_x + box_x, 148 mvwaddch(dialog, box_y, input_x + box_x, ' ');
158 ' ');
159 wmove(dialog, box_y, input_x + box_x); 149 wmove(dialog, box_y, input_x + box_x);
160 wrefresh(dialog); 150 wrefresh(dialog);
161 } 151 }
@@ -165,23 +155,14 @@ dialog_inputbox(const char *title, const char *prompt, int height, int width,
165 if (scroll + input_x < MAX_LEN) { 155 if (scroll + input_x < MAX_LEN) {
166 wattrset(dialog, inputbox_attr); 156 wattrset(dialog, inputbox_attr);
167 instr[scroll + input_x] = key; 157 instr[scroll + input_x] = key;
168 instr[scroll + input_x + 1] = 158 instr[scroll + input_x + 1] = '\0';
169 '\0';
170 if (input_x == box_width - 1) { 159 if (input_x == box_width - 1) {
171 scroll++; 160 scroll++;
172 wmove(dialog, box_y, 161 wmove(dialog, box_y, box_x);
173 box_x); 162 for (i = 0; i < box_width - 1; i++)
174 for (i = 0; 163 waddch(dialog, instr [scroll + i]);
175 i < box_width - 1;
176 i++)
177 waddch(dialog,
178 instr
179 [scroll +
180 i]);
181 } else { 164 } else {
182 wmove(dialog, box_y, 165 wmove(dialog, box_y, input_x++ + box_x);
183 input_x++ +
184 box_x);
185 waddch(dialog, key); 166 waddch(dialog, key);
186 } 167 }
187 wrefresh(dialog); 168 wrefresh(dialog);