aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig
diff options
context:
space:
mode:
authorCheng Renquan <crquan@gmail.com>2011-09-01 13:52:21 -0400
committerMichal Marek <mmarek@suse.cz>2011-09-09 08:40:08 -0400
commite631a57a19e103c3bb59495b236634ec62e2a850 (patch)
treeabcd76bf12c0ea7d6a34f16a0d1b874411d4d827 /scripts/kconfig
parent5ea9f64ffc073bf2882f6aa83b0dad3609b1e67a (diff)
scripts/kconfig/nconf: fix editing long strings
The original dialog_inputbox doesn't work with longer than prompt_width strings, here fixed it in this way: 1) add variable cursor_form_win to record cursor of form_win, keep its value always between [0, prompt_width-1]; reuse the original cursor_position as cursor of the string result, use (cursor_position-cursor_form_win) as begin offset to show part of the string in form_win; Signed-off-by: Cheng Renquan <crquan@gmail.com> Cc: Arnaud Lacombe <lacombar@gmail.com> Cc: Nir Tzachar <nir.tzachar@gmail.com>
Diffstat (limited to 'scripts/kconfig')
-rw-r--r--scripts/kconfig/nconf.gui.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
index d64bc1c24c2..4b9d8b66087 100644
--- a/scripts/kconfig/nconf.gui.c
+++ b/scripts/kconfig/nconf.gui.c
@@ -367,6 +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;
370 char *result = *resultp; 371 char *result = *resultp;
371 372
372 if (strlen(init)+1 > *result_len) { 373 if (strlen(init)+1 > *result_len) {
@@ -410,7 +411,9 @@ int dialog_inputbox(WINDOW *main_window,
410 fill_window(prompt_win, prompt); 411 fill_window(prompt_win, prompt);
411 412
412 mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); 413 mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
413 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);
414 417
415 /* create panels */ 418 /* create panels */
416 panel = new_panel(win); 419 panel = new_panel(win);
@@ -436,6 +439,8 @@ int dialog_inputbox(WINDOW *main_window,
436 &result[cursor_position], 439 &result[cursor_position],
437 len-cursor_position+1); 440 len-cursor_position+1);
438 cursor_position--; 441 cursor_position--;
442 cursor_form_win--;
443 len--;
439 } 444 }
440 break; 445 break;
441 case KEY_DC: 446 case KEY_DC:
@@ -443,18 +448,22 @@ int dialog_inputbox(WINDOW *main_window,
443 memmove(&result[cursor_position], 448 memmove(&result[cursor_position],
444 &result[cursor_position+1], 449 &result[cursor_position+1],
445 len-cursor_position+1); 450 len-cursor_position+1);
451 len--;
446 } 452 }
447 break; 453 break;
448 case KEY_UP: 454 case KEY_UP:
449 case KEY_RIGHT: 455 case KEY_RIGHT:
450 if (cursor_position < len && 456 if (cursor_position < len) {
451 cursor_position < min(*result_len, prompt_width))
452 cursor_position++; 457 cursor_position++;
458 cursor_form_win++;
459 }
453 break; 460 break;
454 case KEY_DOWN: 461 case KEY_DOWN:
455 case KEY_LEFT: 462 case KEY_LEFT:
456 if (cursor_position > 0) 463 if (cursor_position > 0) {
457 cursor_position--; 464 cursor_position--;
465 cursor_form_win--;
466 }
458 break; 467 break;
459 default: 468 default:
460 if ((isgraph(res) || isspace(res))) { 469 if ((isgraph(res) || isspace(res))) {
@@ -470,16 +479,24 @@ int dialog_inputbox(WINDOW *main_window,
470 len-cursor_position+1); 479 len-cursor_position+1);
471 result[cursor_position] = res; 480 result[cursor_position] = res;
472 cursor_position++; 481 cursor_position++;
482 cursor_form_win++;
483 len++;
473 } else { 484 } else {
474 mvprintw(0, 0, "unknown key: %d\n", res); 485 mvprintw(0, 0, "unknown key: %d\n", res);
475 } 486 }
476 break; 487 break;
477 } 488 }
489 if (cursor_form_win < 0)
490 cursor_form_win = 0;
491 else if (cursor_form_win > prompt_width-1)
492 cursor_form_win = prompt_width-1;
493
478 wmove(form_win, 0, 0); 494 wmove(form_win, 0, 0);
479 wclrtoeol(form_win); 495 wclrtoeol(form_win);
480 mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); 496 mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
481 mvwprintw(form_win, 0, 0, "%s", result); 497 mvwprintw(form_win, 0, 0, "%s",
482 wmove(form_win, 0, cursor_position); 498 result + cursor_position-cursor_form_win);
499 wmove(form_win, 0, cursor_form_win);
483 touchwin(win); 500 touchwin(win);
484 refresh_all_windows(main_window); 501 refresh_all_windows(main_window);
485 502