]> rtime.felk.cvut.cz Git - l4.git/blobdiff - l4/tool/kconfig/scripts/kconfig/nconf.gui.c
update
[l4.git] / l4 / tool / kconfig / scripts / kconfig / nconf.gui.c
index a9d9344e136504781c52b0e59361fea6b10be06b..379003c7a2b4d8cef60e25548fcb9567ca3656c5 100644 (file)
@@ -137,7 +137,7 @@ void set_colors()
        if (has_colors()) {
                normal_color_theme();
        } else {
-               /* give deafults */
+               /* give defaults */
                no_colors_theme();
        }
 }
@@ -167,7 +167,7 @@ void print_in_middle(WINDOW *win,
        length = strlen(string);
        temp = (width - length) / 2;
        x = startx + (int)temp;
-       wattrset(win, color);
+       (void) wattrset(win, color);
        mvwprintw(win, y, x, "%s", string);
        refresh();
 }
@@ -297,11 +297,11 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
        set_menu_fore(menu, attributes[DIALOG_MENU_FORE]);
        set_menu_back(menu, attributes[DIALOG_MENU_BACK]);
 
-       wattrset(win, attributes[DIALOG_BOX]);
+       (void) wattrset(win, attributes[DIALOG_BOX]);
        box(win, 0, 0);
 
        /* print message */
-       wattrset(msg_win, attributes[DIALOG_TEXT]);
+       (void) wattrset(msg_win, attributes[DIALOG_TEXT]);
        fill_window(msg_win, msg);
 
        set_menu_win(menu, win);
@@ -356,7 +356,7 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
 
 int dialog_inputbox(WINDOW *main_window,
                const char *title, const char *prompt,
-               const char *init, char *result, int result_len)
+               const char *init, char **resultp, int *result_len)
 {
        int prompt_lines = 0;
        int prompt_width = 0;
@@ -367,7 +367,13 @@ int dialog_inputbox(WINDOW *main_window,
        int i, x, y;
        int res = -1;
        int cursor_position = strlen(init);
+       int cursor_form_win;
+       char *result = *resultp;
 
+       if (strlen(init)+1 > *result_len) {
+               *result_len = strlen(init)+1;
+               *resultp = result = realloc(result, *result_len);
+       }
 
        /* find the widest line of msg: */
        prompt_lines = get_line_no(prompt);
@@ -384,7 +390,7 @@ int dialog_inputbox(WINDOW *main_window,
        y = (LINES-(prompt_lines+4))/2;
        x = (COLS-(prompt_width+4))/2;
 
-       strncpy(result, init, result_len);
+       strncpy(result, init, *result_len);
 
        /* create the windows */
        win = newwin(prompt_lines+6, prompt_width+7, y, x);
@@ -392,20 +398,22 @@ int dialog_inputbox(WINDOW *main_window,
        form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2);
        keypad(form_win, TRUE);
 
-       wattrset(form_win, attributes[INPUT_FIELD]);
+       (void) wattrset(form_win, attributes[INPUT_FIELD]);
 
-       wattrset(win, attributes[INPUT_BOX]);
+       (void) wattrset(win, attributes[INPUT_BOX]);
        box(win, 0, 0);
-       wattrset(win, attributes[INPUT_HEADING]);
+       (void) wattrset(win, attributes[INPUT_HEADING]);
        if (title)
                mvwprintw(win, 0, 3, "%s", title);
 
        /* print message */
-       wattrset(prompt_win, attributes[INPUT_TEXT]);
+       (void) wattrset(prompt_win, attributes[INPUT_TEXT]);
        fill_window(prompt_win, prompt);
 
        mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
-       mvwprintw(form_win, 0, 0, "%s", result);
+       cursor_form_win = min(cursor_position, prompt_width-1);
+       mvwprintw(form_win, 0, 0, "%s",
+                 result + cursor_position-cursor_form_win);
 
        /* create panels */
        panel = new_panel(win);
@@ -431,6 +439,8 @@ int dialog_inputbox(WINDOW *main_window,
                                                &result[cursor_position],
                                                len-cursor_position+1);
                                cursor_position--;
+                               cursor_form_win--;
+                               len--;
                        }
                        break;
                case KEY_DC:
@@ -438,38 +448,63 @@ int dialog_inputbox(WINDOW *main_window,
                                memmove(&result[cursor_position],
                                                &result[cursor_position+1],
                                                len-cursor_position+1);
+                               len--;
                        }
                        break;
                case KEY_UP:
                case KEY_RIGHT:
-                       if (cursor_position < len &&
-                           cursor_position < min(result_len, prompt_width))
+                       if (cursor_position < len) {
                                cursor_position++;
+                               cursor_form_win++;
+                       }
                        break;
                case KEY_DOWN:
                case KEY_LEFT:
-                       if (cursor_position > 0)
+                       if (cursor_position > 0) {
                                cursor_position--;
+                               cursor_form_win--;
+                       }
+                       break;
+               case KEY_HOME:
+                       cursor_position = 0;
+                       cursor_form_win = 0;
+                       break;
+               case KEY_END:
+                       cursor_position = len;
+                       cursor_form_win = min(cursor_position, prompt_width-1);
                        break;
                default:
-                       if ((isgraph(res) || isspace(res)) &&
-                                       len-2 < result_len) {
+                       if ((isgraph(res) || isspace(res))) {
+                               /* one for new char, one for '\0' */
+                               if (len+2 > *result_len) {
+                                       *result_len = len+2;
+                                       *resultp = result = realloc(result,
+                                                               *result_len);
+                               }
                                /* insert the char at the proper position */
                                memmove(&result[cursor_position+1],
                                                &result[cursor_position],
-                                               len+1);
+                                               len-cursor_position+1);
                                result[cursor_position] = res;
                                cursor_position++;
+                               cursor_form_win++;
+                               len++;
                        } else {
-                               mvprintw(0, 0, "unknow key: %d\n", res);
+                               mvprintw(0, 0, "unknown key: %d\n", res);
                        }
                        break;
                }
+               if (cursor_form_win < 0)
+                       cursor_form_win = 0;
+               else if (cursor_form_win > prompt_width-1)
+                       cursor_form_win = prompt_width-1;
+
                wmove(form_win, 0, 0);
                wclrtoeol(form_win);
                mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
-               mvwprintw(form_win, 0, 0, "%s", result);
-               wmove(form_win, 0, cursor_position);
+               mvwprintw(form_win, 0, 0, "%s",
+                       result + cursor_position-cursor_form_win);
+               wmove(form_win, 0, cursor_form_win);
                touchwin(win);
                refresh_all_windows(main_window);
 
@@ -531,7 +566,7 @@ void show_scroll_win(WINDOW *main_window,
 
        /* create the pad */
        pad = newpad(total_lines+10, total_cols+10);
-       wattrset(pad, attributes[SCROLLWIN_TEXT]);
+       (void) wattrset(pad, attributes[SCROLLWIN_TEXT]);
        fill_window(pad, text);
 
        win_lines = min(total_lines+4, LINES-2);
@@ -546,9 +581,9 @@ void show_scroll_win(WINDOW *main_window,
        win = newwin(win_lines, win_cols, y, x);
        keypad(win, TRUE);
        /* show the help in the help window, and show the help panel */
-       wattrset(win, attributes[SCROLLWIN_BOX]);
+       (void) wattrset(win, attributes[SCROLLWIN_BOX]);
        box(win, 0, 0);
-       wattrset(win, attributes[SCROLLWIN_HEADING]);
+       (void) wattrset(win, attributes[SCROLLWIN_HEADING]);
        mvwprintw(win, 0, 3, " %s ", title);
        panel = new_panel(win);
 
@@ -569,9 +604,11 @@ void show_scroll_win(WINDOW *main_window,
                switch (res) {
                case KEY_NPAGE:
                case ' ':
+               case 'd':
                        start_y += text_lines-2;
                        break;
                case KEY_PPAGE:
+               case 'u':
                        start_y -= text_lines+2;
                        break;
                case KEY_HOME:
@@ -597,10 +634,10 @@ void show_scroll_win(WINDOW *main_window,
                        start_x++;
                        break;
                }
-               if (res == 10 || res == 27 || res == 'q'
-                   || res == KEY_F(F_BACK) || res == KEY_F(F_EXIT)) {
+               if (res == 10 || res == 27 || res == 'q' ||
+                       res == KEY_F(F_HELP) || res == KEY_F(F_BACK) ||
+                       res == KEY_F(F_EXIT))
                        break;
-               }
                if (start_y < 0)
                        start_y = 0;
                if (start_y >= total_lines-text_lines)