diff options
Diffstat (limited to 'scripts/kconfig/nconf.gui.c')
-rw-r--r-- | scripts/kconfig/nconf.gui.c | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index f8137b3a5382..3b18dd839668 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c | |||
@@ -356,7 +356,7 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...) | |||
356 | 356 | ||
357 | int dialog_inputbox(WINDOW *main_window, | 357 | int dialog_inputbox(WINDOW *main_window, |
358 | const char *title, const char *prompt, | 358 | const char *title, const char *prompt, |
359 | const char *init, char *result, int result_len) | 359 | const char *init, char **resultp, int *result_len) |
360 | { | 360 | { |
361 | int prompt_lines = 0; | 361 | int prompt_lines = 0; |
362 | int prompt_width = 0; | 362 | int prompt_width = 0; |
@@ -367,7 +367,13 @@ int dialog_inputbox(WINDOW *main_window, | |||
367 | int i, x, y; | 367 | int i, x, y; |
368 | int res = -1; | 368 | int res = -1; |
369 | int cursor_position = strlen(init); | 369 | int cursor_position = strlen(init); |
370 | int cursor_form_win; | ||
371 | char *result = *resultp; | ||
370 | 372 | ||
373 | if (strlen(init)+1 > *result_len) { | ||
374 | *result_len = strlen(init)+1; | ||
375 | *resultp = result = realloc(result, *result_len); | ||
376 | } | ||
371 | 377 | ||
372 | /* find the widest line of msg: */ | 378 | /* find the widest line of msg: */ |
373 | prompt_lines = get_line_no(prompt); | 379 | prompt_lines = get_line_no(prompt); |
@@ -384,7 +390,7 @@ int dialog_inputbox(WINDOW *main_window, | |||
384 | y = (LINES-(prompt_lines+4))/2; | 390 | y = (LINES-(prompt_lines+4))/2; |
385 | x = (COLS-(prompt_width+4))/2; | 391 | x = (COLS-(prompt_width+4))/2; |
386 | 392 | ||
387 | strncpy(result, init, result_len); | 393 | strncpy(result, init, *result_len); |
388 | 394 | ||
389 | /* create the windows */ | 395 | /* create the windows */ |
390 | win = newwin(prompt_lines+6, prompt_width+7, y, x); | 396 | win = newwin(prompt_lines+6, prompt_width+7, y, x); |
@@ -405,7 +411,9 @@ int dialog_inputbox(WINDOW *main_window, | |||
405 | fill_window(prompt_win, prompt); | 411 | fill_window(prompt_win, prompt); |
406 | 412 | ||
407 | mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); | 413 | mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); |
408 | mvwprintw(form_win, 0, 0, "%s", result); | 414 | cursor_form_win = min(cursor_position, prompt_width-1); |
415 | mvwprintw(form_win, 0, 0, "%s", | ||
416 | result + cursor_position-cursor_form_win); | ||
409 | 417 | ||
410 | /* create panels */ | 418 | /* create panels */ |
411 | panel = new_panel(win); | 419 | panel = new_panel(win); |
@@ -431,6 +439,8 @@ int dialog_inputbox(WINDOW *main_window, | |||
431 | &result[cursor_position], | 439 | &result[cursor_position], |
432 | len-cursor_position+1); | 440 | len-cursor_position+1); |
433 | cursor_position--; | 441 | cursor_position--; |
442 | cursor_form_win--; | ||
443 | len--; | ||
434 | } | 444 | } |
435 | break; | 445 | break; |
436 | case KEY_DC: | 446 | case KEY_DC: |
@@ -438,38 +448,63 @@ int dialog_inputbox(WINDOW *main_window, | |||
438 | memmove(&result[cursor_position], | 448 | memmove(&result[cursor_position], |
439 | &result[cursor_position+1], | 449 | &result[cursor_position+1], |
440 | len-cursor_position+1); | 450 | len-cursor_position+1); |
451 | len--; | ||
441 | } | 452 | } |
442 | break; | 453 | break; |
443 | case KEY_UP: | 454 | case KEY_UP: |
444 | case KEY_RIGHT: | 455 | case KEY_RIGHT: |
445 | if (cursor_position < len && | 456 | if (cursor_position < len) { |
446 | cursor_position < min(result_len, prompt_width)) | ||
447 | cursor_position++; | 457 | cursor_position++; |
458 | cursor_form_win++; | ||
459 | } | ||
448 | break; | 460 | break; |
449 | case KEY_DOWN: | 461 | case KEY_DOWN: |
450 | case KEY_LEFT: | 462 | case KEY_LEFT: |
451 | if (cursor_position > 0) | 463 | if (cursor_position > 0) { |
452 | cursor_position--; | 464 | cursor_position--; |
465 | cursor_form_win--; | ||
466 | } | ||
467 | break; | ||
468 | case KEY_HOME: | ||
469 | cursor_position = 0; | ||
470 | cursor_form_win = 0; | ||
471 | break; | ||
472 | case KEY_END: | ||
473 | cursor_position = len; | ||
474 | cursor_form_win = min(cursor_position, prompt_width-1); | ||
453 | break; | 475 | break; |
454 | default: | 476 | default: |
455 | if ((isgraph(res) || isspace(res)) && | 477 | if ((isgraph(res) || isspace(res))) { |
456 | len-2 < result_len) { | 478 | /* one for new char, one for '\0' */ |
479 | if (len+2 > *result_len) { | ||
480 | *result_len = len+2; | ||
481 | *resultp = result = realloc(result, | ||
482 | *result_len); | ||
483 | } | ||
457 | /* insert the char at the proper position */ | 484 | /* insert the char at the proper position */ |
458 | memmove(&result[cursor_position+1], | 485 | memmove(&result[cursor_position+1], |
459 | &result[cursor_position], | 486 | &result[cursor_position], |
460 | len+1); | 487 | len-cursor_position+1); |
461 | result[cursor_position] = res; | 488 | result[cursor_position] = res; |
462 | cursor_position++; | 489 | cursor_position++; |
490 | cursor_form_win++; | ||
491 | len++; | ||
463 | } else { | 492 | } else { |
464 | mvprintw(0, 0, "unknow key: %d\n", res); | 493 | mvprintw(0, 0, "unknown key: %d\n", res); |
465 | } | 494 | } |
466 | break; | 495 | break; |
467 | } | 496 | } |
497 | if (cursor_form_win < 0) | ||
498 | cursor_form_win = 0; | ||
499 | else if (cursor_form_win > prompt_width-1) | ||
500 | cursor_form_win = prompt_width-1; | ||
501 | |||
468 | wmove(form_win, 0, 0); | 502 | wmove(form_win, 0, 0); |
469 | wclrtoeol(form_win); | 503 | wclrtoeol(form_win); |
470 | mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); | 504 | mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); |
471 | mvwprintw(form_win, 0, 0, "%s", result); | 505 | mvwprintw(form_win, 0, 0, "%s", |
472 | wmove(form_win, 0, cursor_position); | 506 | result + cursor_position-cursor_form_win); |
507 | wmove(form_win, 0, cursor_form_win); | ||
473 | touchwin(win); | 508 | touchwin(win); |
474 | refresh_all_windows(main_window); | 509 | refresh_all_windows(main_window); |
475 | 510 | ||