Re: [PATCH 4/5] scripts/kconfig/nconf: fix editing long strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hello.

On Tue, Aug 30, 2011 at 7:59 AM, Arnaud Lacombe <lacombar@xxxxxxxxx> wrote:
> Hi,
>
> On Mon, Aug 29, 2011 at 7:56 PM, Cheng Renquan <crquan@xxxxxxxxx> wrote:
>> 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];
>>   keep the original cursor_position as cursor of the string result,
>>   for short strings, cursor_form_win is identical to cursor_position;
>>   for long strings, use (cursor_position-cursor_form_win) as begin offset
>>   to show part of the string in form_win;
>>
>
>> 2) whenever cursor of form_win is near (by 3 chars) to left or right edge
>>   of form_win, make a auto scroll by half prompt_width, to make this one
>>   line string editor more fun to use;
>>
> I am not a huge fan of this behavior, it seems a bit chaotic and
> unnatural to me.


I agree with Arnaud. Jumping the line is chaotic. I believe that
scrolling the string view one character left (or right)-wise is a
better solution.


> menuconfig's (partial) support of long string seem more stable. When
> you erase a long string, the cursor move left. When you end up on the
> edge, the window slide left fully, which let you see either a full
> window again, or the beginning of the string. Unfortunately, you
> cannot scroll within the string, but I would expect that when you
> reach the right of the window, and continue typing, to see the window
> moves right, without this "come back" effect.
>
> Beside that, I agree, it's a huge improvement :)
>
>  - Arnaud
>
>> 3) update len for later cursor_form_win correct calculation;
>>
>> Signed-off-by: Cheng Renquan <crquan@xxxxxxxxx>
>> ---
>>  scripts/kconfig/nconf.gui.c |   43 +++++++++++++++++++++++++++++++++++++------
>>  1 files changed, 37 insertions(+), 6 deletions(-)
>>
>> diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
>> index bc482ad..62a41d1 100644
>> --- a/scripts/kconfig/nconf.gui.c
>> +++ b/scripts/kconfig/nconf.gui.c
>> @@ -367,6 +367,7 @@ int dialog_inputbox(WINDOW *main_window,
>>        int i, x, y;
>>        int res = -1;
>>        int cursor_position = strlen(init);
>> +       int cursor_form_win;
>>
>>        if (strlen(init) > *result_len) {
>>                do {
>> @@ -413,7 +414,9 @@ int dialog_inputbox(WINDOW *main_window,
>>        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);
>> @@ -439,6 +442,8 @@ int dialog_inputbox(WINDOW *main_window,
>>                                                &result[cursor_position],
>>                                                len-cursor_position+1);
>>                                cursor_position--;
>> +                               cursor_form_win--;
>> +                               len--;
>>                        }
>>                        break;
>>                case KEY_DC:
>> @@ -446,18 +451,22 @@ 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;
>>                default:
>>                        if ((isgraph(res) || isspace(res))) {
>> @@ -475,16 +484,38 @@ int dialog_inputbox(WINDOW *main_window,
>>                                                len-cursor_position+1);
>>                                result[cursor_position] = res;
>>                                cursor_position++;
>> +                               cursor_form_win++;
>> +                               len++;
>>                        } else {
>>                                mvprintw(0, 0, "unknown key: %d\n", res);
>>                        }
>>                        break;
>>                }
>> +               if (len <= prompt_width-1)
>> +                       cursor_form_win = cursor_position;
>> +               else {
>> +                       if (cursor_form_win <= 3)
>> +                               cursor_form_win += prompt_width/2;
>> +                       else if (cursor_form_win >= prompt_width-3)
>> +                               cursor_form_win -= prompt_width/2;
>> +
>> +                       if (cursor_form_win < 0)
>> +                               cursor_form_win = 0;
>> +                       else if (cursor_form_win >= prompt_width-1)
>> +                               cursor_form_win = prompt_width-1;
>> +
>> +                       if (cursor_form_win > cursor_position)
>> +                               cursor_form_win = cursor_position;
>> +                       if (cursor_form_win < (prompt_width-1) - (len-cursor_position))
>> +                               cursor_form_win = (prompt_width-1) - (len-cursor_position);
>> +               }
>> +
>>                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);
>>
>> --
>> 1.7.6
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
>> the body of a message to majordomo@xxxxxxxxxxxxxxx
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Free Online Dating]     [Linux Kernel]     [Linux SCSI]     [XFree86]

Add to Google Powered by Linux