aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorWang YanQing <udknight@gmail.com>2012-12-17 09:38:02 -0500
committerYann E. MORIN <yann.morin.1998@free.fr>2012-12-25 17:42:37 -0500
commit87727d453b4677a21312712c8a4bb5dcd81a1ebe (patch)
tree7ce0739de15a48d86a67ad72dc63871c5525976a /scripts
parent169743264f8100a39042a4d6bec44dabb2e2e624 (diff)
menuconfig:inputbox: support navigate input position
This patch add support navigate input position *inside* the input field with LEFT/RIGHT, so it is possible to modify the text in place. Signed-off-by: Wang YanQing <udknight@gmail.com> Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/kconfig/lxdialog/inputbox.c121
1 files changed, 92 insertions, 29 deletions
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index dd8e587c50e2..21404a04d7c3 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -45,7 +45,8 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
45 const char *init) 45 const char *init)
46{ 46{
47 int i, x, y, box_y, box_x, box_width; 47 int i, x, y, box_y, box_x, box_width;
48 int input_x = 0, scroll = 0, key = 0, button = -1; 48 int input_x = 0, key = 0, button = -1;
49 int show_x, len, pos;
49 char *instr = dialog_input_result; 50 char *instr = dialog_input_result;
50 WINDOW *dialog; 51 WINDOW *dialog;
51 52
@@ -97,14 +98,17 @@ do_resize:
97 wmove(dialog, box_y, box_x); 98 wmove(dialog, box_y, box_x);
98 wattrset(dialog, dlg.inputbox.atr); 99 wattrset(dialog, dlg.inputbox.atr);
99 100
100 input_x = strlen(instr); 101 len = strlen(instr);
102 pos = len;
101 103
102 if (input_x >= box_width) { 104 if (len >= box_width) {
103 scroll = input_x - box_width + 1; 105 show_x = len - box_width + 1;
104 input_x = box_width - 1; 106 input_x = box_width - 1;
105 for (i = 0; i < box_width - 1; i++) 107 for (i = 0; i < box_width - 1; i++)
106 waddch(dialog, instr[scroll + i]); 108 waddch(dialog, instr[show_x + i]);
107 } else { 109 } else {
110 show_x = 0;
111 input_x = len;
108 waddstr(dialog, instr); 112 waddstr(dialog, instr);
109 } 113 }
110 114
@@ -121,45 +125,104 @@ do_resize:
121 case KEY_UP: 125 case KEY_UP:
122 case KEY_DOWN: 126 case KEY_DOWN:
123 break; 127 break;
124 case KEY_LEFT:
125 continue;
126 case KEY_RIGHT:
127 continue;
128 case KEY_BACKSPACE: 128 case KEY_BACKSPACE:
129 case 127: 129 case 127:
130 if (input_x || scroll) { 130 if (pos) {
131 wattrset(dialog, dlg.inputbox.atr); 131 wattrset(dialog, dlg.inputbox.atr);
132 if (!input_x) { 132 if (input_x == 0) {
133 scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1); 133 show_x--;
134 wmove(dialog, box_y, box_x);
135 for (i = 0; i < box_width; i++)
136 waddch(dialog,
137 instr[scroll + input_x + i] ?
138 instr[scroll + input_x + i] : ' ');
139 input_x = strlen(instr) - scroll;
140 } else 134 } else
141 input_x--; 135 input_x--;
142 instr[scroll + input_x] = '\0'; 136
143 mvwaddch(dialog, box_y, input_x + box_x, ' '); 137 if (pos < len) {
138 for (i = pos - 1; i < len; i++) {
139 instr[i] = instr[i+1];
140 }
141 }
142
143 pos--;
144 len--;
145 instr[len] = '\0';
146 wmove(dialog, box_y, box_x);
147 for (i = 0; i < box_width; i++) {
148 if (!instr[show_x + i]) {
149 waddch(dialog, ' ');
150 break;
151 }
152 waddch(dialog, instr[show_x + i]);
153 }
144 wmove(dialog, box_y, input_x + box_x); 154 wmove(dialog, box_y, input_x + box_x);
145 wrefresh(dialog); 155 wrefresh(dialog);
146 } 156 }
147 continue; 157 continue;
158 case KEY_LEFT:
159 if (pos > 0) {
160 if (input_x > 0) {
161 wmove(dialog, box_y, --input_x + box_x);
162 } else if (input_x == 0) {
163 show_x--;
164 wmove(dialog, box_y, box_x);
165 for (i = 0; i < box_width; i++) {
166 if (!instr[show_x + i]) {
167 waddch(dialog, ' ');
168 break;
169 }
170 waddch(dialog, instr[show_x + i]);
171 }
172 wmove(dialog, box_y, box_x);
173 }
174 pos--;
175 }
176 continue;
177 case KEY_RIGHT:
178 if (pos < len) {
179 if (input_x < box_width - 1) {
180 wmove(dialog, box_y, ++input_x + box_x);
181 } else if (input_x == box_width - 1) {
182 show_x++;
183 wmove(dialog, box_y, box_x);
184 for (i = 0; i < box_width; i++) {
185 if (!instr[show_x + i]) {
186 waddch(dialog, ' ');
187 break;
188 }
189 waddch(dialog, instr[show_x + i]);
190 }
191 wmove(dialog, box_y, input_x + box_x);
192 }
193 pos++;
194 }
195 continue;
148 default: 196 default:
149 if (key < 0x100 && isprint(key)) { 197 if (key < 0x100 && isprint(key)) {
150 if (scroll + input_x < MAX_LEN) { 198 if (len < MAX_LEN) {
151 wattrset(dialog, dlg.inputbox.atr); 199 wattrset(dialog, dlg.inputbox.atr);
152 instr[scroll + input_x] = key; 200 if (pos < len) {
153 instr[scroll + input_x + 1] = '\0'; 201 for (i = len; i > pos; i--)
202 instr[i] = instr[i-1];
203 instr[pos] = key;
204 } else {
205 instr[len] = key;
206 }
207 pos++;
208 len++;
209 instr[len] = '\0';
210
154 if (input_x == box_width - 1) { 211 if (input_x == box_width - 1) {
155 scroll++; 212 show_x++;
156 wmove(dialog, box_y, box_x);
157 for (i = 0; i < box_width - 1; i++)
158 waddch(dialog, instr [scroll + i]);
159 } else { 213 } else {
160 wmove(dialog, box_y, input_x++ + box_x); 214 input_x++;
161 waddch(dialog, key); 215 }
216
217 wmove(dialog, box_y, box_x);
218 for (i = 0; i < box_width; i++) {
219 if (!instr[show_x + i]) {
220 waddch(dialog, ' ');
221 break;
222 }
223 waddch(dialog, instr[show_x + i]);
162 } 224 }
225 wmove(dialog, box_y, input_x + box_x);
163 wrefresh(dialog); 226 wrefresh(dialog);
164 } else 227 } else
165 flash(); /* Alarm user about overflow */ 228 flash(); /* Alarm user about overflow */