2010-06-03 07:22:19

by Li Zefan

[permalink] [raw]
Subject: [PATCH 1/2] menuconfig: fix to center checklist correctly in a corner case

Run:
make ARCH=arm menuconfig

And then select "System Type" -> "ARM system type". The kconfig
"choice" menu at this point looks empty.

It's because config ARCH_S3C2410 has a long prompt:

config ARCH_S3C2410
bool "Samsung S3C2410, S3C2412, S3C2413, S3C2416, S3C2440, S3C2442, S3C2443, S3C2450"
...

menuconfig centers the checklist according to this prompt without
considering the width of the list, and then things get wrong.

Reported-by: Nobin Mathew <[email protected]>
Signed-off-by: Li Zefan <[email protected]>
---

Please queue these 2 patches for 2.6.35.

---
scripts/kconfig/lxdialog/checklist.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index bcc6f19..c92a05a 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -175,6 +175,7 @@ do_resize:
check_x = 0;
item_foreach()
check_x = MAX(check_x, strlen(item_str()) + 4);
+ check_x = MIN(check_x, list_width);

check_x = (list_width - check_x) / 2;
item_x = check_x + 4;
--
1.6.3


2010-06-03 07:22:32

by Li Zefan

[permalink] [raw]
Subject: [PATCH 2/2] menuconfig: truncate list items

Truncate list items to fit in a single line, otherwise those items
which have long prompts will cover some other items.

This follows the behavior of menubox.

Signed-off-by: Li Zefan <[email protected]>
---
scripts/kconfig/lxdialog/checklist.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index c92a05a..a2eb80f 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -31,6 +31,10 @@ static int list_width, check_x, item_x;
static void print_item(WINDOW * win, int choice, int selected)
{
int i;
+ char *list_item = malloc(list_width + 1);
+
+ strncpy(list_item, item_str(), list_width - item_x);
+ list_item[list_width - item_x] = '\0';

/* Clear 'residue' of last item */
wattrset(win, dlg.menubox.atr);
@@ -45,13 +49,14 @@ static void print_item(WINDOW * win, int choice, int selected)
wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' ');

wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr);
- mvwaddch(win, choice, item_x, item_str()[0]);
+ mvwaddch(win, choice, item_x, list_item[0]);
wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
- waddstr(win, (char *)item_str() + 1);
+ waddstr(win, list_item + 1);
if (selected) {
wmove(win, choice, check_x + 1);
wrefresh(win);
}
+ free(list_item);
}

/*
--
1.6.3

2010-06-03 16:33:20

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH 1/2] menuconfig: fix to center checklist correctly in a corner case

On 06/03/10 00:24, Li Zefan wrote:
> Run:
> make ARCH=arm menuconfig
>
> And then select "System Type" -> "ARM system type". The kconfig
> "choice" menu at this point looks empty.
>
> It's because config ARCH_S3C2410 has a long prompt:
>
> config ARCH_S3C2410
> bool "Samsung S3C2410, S3C2412, S3C2413, S3C2416, S3C2440, S3C2442, S3C2443, S3C2450"
> ...
>
> menuconfig centers the checklist according to this prompt without
> considering the width of the list, and then things get wrong.
>
> Reported-by: Nobin Mathew <[email protected]>
> Signed-off-by: Li Zefan <[email protected]>
> ---
>
> Please queue these 2 patches for 2.6.35.

Tested-by: Randy Dunlap <[email protected]>

Thanks.

> ---
> scripts/kconfig/lxdialog/checklist.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
> index bcc6f19..c92a05a 100644
> --- a/scripts/kconfig/lxdialog/checklist.c
> +++ b/scripts/kconfig/lxdialog/checklist.c
> @@ -175,6 +175,7 @@ do_resize:
> check_x = 0;
> item_foreach()
> check_x = MAX(check_x, strlen(item_str()) + 4);
> + check_x = MIN(check_x, list_width);
>
> check_x = (list_width - check_x) / 2;
> item_x = check_x + 4;


--
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

2010-06-03 16:34:47

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH 2/2] menuconfig: truncate list items

On 06/03/10 00:24, Li Zefan wrote:
> Truncate list items to fit in a single line, otherwise those items
> which have long prompts will cover some other items.
>
> This follows the behavior of menubox.
>
> Signed-off-by: Li Zefan <[email protected]>

Thanks :)

Tested-by: Randy Dunlap <[email protected]>

Ben, the Samsung S3C24* prompt still gets truncated with this patch (when using
an 80-column wide xterm). If you care about seeing all of the models,
you might want to shorten the prompt.


> ---
> scripts/kconfig/lxdialog/checklist.c | 9 +++++++--
> 1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
> index c92a05a..a2eb80f 100644
> --- a/scripts/kconfig/lxdialog/checklist.c
> +++ b/scripts/kconfig/lxdialog/checklist.c
> @@ -31,6 +31,10 @@ static int list_width, check_x, item_x;
> static void print_item(WINDOW * win, int choice, int selected)
> {
> int i;
> + char *list_item = malloc(list_width + 1);
> +
> + strncpy(list_item, item_str(), list_width - item_x);
> + list_item[list_width - item_x] = '\0';
>
> /* Clear 'residue' of last item */
> wattrset(win, dlg.menubox.atr);
> @@ -45,13 +49,14 @@ static void print_item(WINDOW * win, int choice, int selected)
> wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' ');
>
> wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr);
> - mvwaddch(win, choice, item_x, item_str()[0]);
> + mvwaddch(win, choice, item_x, list_item[0]);
> wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
> - waddstr(win, (char *)item_str() + 1);
> + waddstr(win, list_item + 1);
> if (selected) {
> wmove(win, choice, check_x + 1);
> wrefresh(win);
> }
> + free(list_item);
> }
>
> /*


--
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

2010-06-04 00:55:11

by Li Zefan

[permalink] [raw]
Subject: Re: [PATCH 2/2] menuconfig: truncate list items

Randy Dunlap wrote:
> On 06/03/10 00:24, Li Zefan wrote:
>> Truncate list items to fit in a single line, otherwise those items
>> which have long prompts will cover some other items.
>>
>> This follows the behavior of menubox.
>>
>> Signed-off-by: Li Zefan <[email protected]>
>
> Thanks :)
>
> Tested-by: Randy Dunlap <[email protected]>
>
> Ben, the Samsung S3C24* prompt still gets truncated with this patch (when using
> an 80-column wide xterm). If you care about seeing all of the models,
> you might want to shorten the prompt.
>

An alterative is to print the truncated string and end it with "...":

( ) Samsung S3C2410, S3C2412, S3C2413, S3C2416, S3C2440...