diff options
Diffstat (limited to 'scripts/kconfig/nconf.gui.c')
| -rw-r--r-- | scripts/kconfig/nconf.gui.c | 67 |
1 files changed, 15 insertions, 52 deletions
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index 379003c7a2b..f8137b3a538 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 **resultp, int *result_len) | 359 | const char *init, char *result, 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,13 +367,7 @@ 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; | ||
| 372 | 370 | ||
| 373 | if (strlen(init)+1 > *result_len) { | ||
| 374 | *result_len = strlen(init)+1; | ||
| 375 | *resultp = result = realloc(result, *result_len); | ||
| 376 | } | ||
| 377 | 371 | ||
| 378 | /* find the widest line of msg: */ | 372 | /* find the widest line of msg: */ |
| 379 | prompt_lines = get_line_no(prompt); | 373 | prompt_lines = get_line_no(prompt); |
| @@ -390,7 +384,7 @@ int dialog_inputbox(WINDOW *main_window, | |||
| 390 | y = (LINES-(prompt_lines+4))/2; | 384 | y = (LINES-(prompt_lines+4))/2; |
| 391 | x = (COLS-(prompt_width+4))/2; | 385 | x = (COLS-(prompt_width+4))/2; |
| 392 | 386 | ||
| 393 | strncpy(result, init, *result_len); | 387 | strncpy(result, init, result_len); |
| 394 | 388 | ||
| 395 | /* create the windows */ | 389 | /* create the windows */ |
| 396 | win = newwin(prompt_lines+6, prompt_width+7, y, x); | 390 | win = newwin(prompt_lines+6, prompt_width+7, y, x); |
| @@ -411,9 +405,7 @@ int dialog_inputbox(WINDOW *main_window, | |||
| 411 | fill_window(prompt_win, prompt); | 405 | fill_window(prompt_win, prompt); |
| 412 | 406 | ||
| 413 | mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); | 407 | mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); |
| 414 | cursor_form_win = min(cursor_position, prompt_width-1); | 408 | mvwprintw(form_win, 0, 0, "%s", result); |
| 415 | mvwprintw(form_win, 0, 0, "%s", | ||
| 416 | result + cursor_position-cursor_form_win); | ||
| 417 | 409 | ||
| 418 | /* create panels */ | 410 | /* create panels */ |
| 419 | panel = new_panel(win); | 411 | panel = new_panel(win); |
| @@ -439,8 +431,6 @@ int dialog_inputbox(WINDOW *main_window, | |||
| 439 | &result[cursor_position], | 431 | &result[cursor_position], |
| 440 | len-cursor_position+1); | 432 | len-cursor_position+1); |
| 441 | cursor_position--; | 433 | cursor_position--; |
| 442 | cursor_form_win--; | ||
| 443 | len--; | ||
| 444 | } | 434 | } |
| 445 | break; | 435 | break; |
| 446 | case KEY_DC: | 436 | case KEY_DC: |
| @@ -448,63 +438,38 @@ int dialog_inputbox(WINDOW *main_window, | |||
| 448 | memmove(&result[cursor_position], | 438 | memmove(&result[cursor_position], |
| 449 | &result[cursor_position+1], | 439 | &result[cursor_position+1], |
| 450 | len-cursor_position+1); | 440 | len-cursor_position+1); |
| 451 | len--; | ||
| 452 | } | 441 | } |
| 453 | break; | 442 | break; |
| 454 | case KEY_UP: | 443 | case KEY_UP: |
| 455 | case KEY_RIGHT: | 444 | case KEY_RIGHT: |
| 456 | if (cursor_position < len) { | 445 | if (cursor_position < len && |
| 446 | cursor_position < min(result_len, prompt_width)) | ||
| 457 | cursor_position++; | 447 | cursor_position++; |
| 458 | cursor_form_win++; | ||
| 459 | } | ||
| 460 | break; | 448 | break; |
| 461 | case KEY_DOWN: | 449 | case KEY_DOWN: |
| 462 | case KEY_LEFT: | 450 | case KEY_LEFT: |
| 463 | if (cursor_position > 0) { | 451 | if (cursor_position > 0) |
| 464 | cursor_position--; | 452 | 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); | ||
| 475 | break; | 453 | break; |
| 476 | default: | 454 | default: |
| 477 | if ((isgraph(res) || isspace(res))) { | 455 | if ((isgraph(res) || isspace(res)) && |
| 478 | /* one for new char, one for '\0' */ | 456 | len-2 < result_len) { |
| 479 | if (len+2 > *result_len) { | ||
| 480 | *result_len = len+2; | ||
| 481 | *resultp = result = realloc(result, | ||
| 482 | *result_len); | ||
| 483 | } | ||
| 484 | /* insert the char at the proper position */ | 457 | /* insert the char at the proper position */ |
| 485 | memmove(&result[cursor_position+1], | 458 | memmove(&result[cursor_position+1], |
| 486 | &result[cursor_position], | 459 | &result[cursor_position], |
| 487 | len-cursor_position+1); | 460 | len+1); |
| 488 | result[cursor_position] = res; | 461 | result[cursor_position] = res; |
| 489 | cursor_position++; | 462 | cursor_position++; |
| 490 | cursor_form_win++; | ||
| 491 | len++; | ||
| 492 | } else { | 463 | } else { |
| 493 | mvprintw(0, 0, "unknown key: %d\n", res); | 464 | mvprintw(0, 0, "unknow key: %d\n", res); |
| 494 | } | 465 | } |
| 495 | break; | 466 | break; |
| 496 | } | 467 | } |
| 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 | |||
| 502 | wmove(form_win, 0, 0); | 468 | wmove(form_win, 0, 0); |
| 503 | wclrtoeol(form_win); | 469 | wclrtoeol(form_win); |
| 504 | mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); | 470 | mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); |
| 505 | mvwprintw(form_win, 0, 0, "%s", | 471 | mvwprintw(form_win, 0, 0, "%s", result); |
| 506 | result + cursor_position-cursor_form_win); | 472 | wmove(form_win, 0, cursor_position); |
| 507 | wmove(form_win, 0, cursor_form_win); | ||
| 508 | touchwin(win); | 473 | touchwin(win); |
| 509 | refresh_all_windows(main_window); | 474 | refresh_all_windows(main_window); |
| 510 | 475 | ||
| @@ -604,11 +569,9 @@ void show_scroll_win(WINDOW *main_window, | |||
| 604 | switch (res) { | 569 | switch (res) { |
| 605 | case KEY_NPAGE: | 570 | case KEY_NPAGE: |
| 606 | case ' ': | 571 | case ' ': |
| 607 | case 'd': | ||
| 608 | start_y += text_lines-2; | 572 | start_y += text_lines-2; |
| 609 | break; | 573 | break; |
| 610 | case KEY_PPAGE: | 574 | case KEY_PPAGE: |
| 611 | case 'u': | ||
| 612 | start_y -= text_lines+2; | 575 | start_y -= text_lines+2; |
| 613 | break; | 576 | break; |
| 614 | case KEY_HOME: | 577 | case KEY_HOME: |
| @@ -634,10 +597,10 @@ void show_scroll_win(WINDOW *main_window, | |||
| 634 | start_x++; | 597 | start_x++; |
| 635 | break; | 598 | break; |
| 636 | } | 599 | } |
| 637 | if (res == 10 || res == 27 || res == 'q' || | 600 | if (res == 10 || res == 27 || res == 'q' |
| 638 | res == KEY_F(F_HELP) || res == KEY_F(F_BACK) || | 601 | || res == KEY_F(F_BACK) || res == KEY_F(F_EXIT)) { |
| 639 | res == KEY_F(F_EXIT)) | ||
| 640 | break; | 602 | break; |
| 603 | } | ||
| 641 | if (start_y < 0) | 604 | if (start_y < 0) |
| 642 | start_y = 0; | 605 | start_y = 0; |
| 643 | if (start_y >= total_lines-text_lines) | 606 | if (start_y >= total_lines-text_lines) |
