2024-02-28 06:04:20

by Tomasz Figa

[permalink] [raw]
Subject: [PATCH v2] kconfig: menuconfig: Make hidden options show with different color

When hidden options are toggled on (using 'z'), the number of options
on the screen can be overwhelming and may make it hard to distinguish
between available and hidden ones. Make them easier to distinguish by
displaying the hidden one with a different color (COLOR_YELLOW for color
themes and A_DIM for mono).

Signed-off-by: Tomasz Figa <[email protected]>
---
scripts/kconfig/lxdialog/dialog.h | 5 +++++
scripts/kconfig/lxdialog/menubox.c | 12 ++++++++----
scripts/kconfig/lxdialog/util.c | 19 +++++++++++++++++++
scripts/kconfig/mconf.c | 18 ++++++++++++++++++
4 files changed, 50 insertions(+), 4 deletions(-)

Changes from v1:
(https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/)
* Replaced A_DIM for color themes with COLOR_YELLOW, because the former
has no effect to black text on some commonly used terminals, e.g.
gnome-terminal, foot. Reported by Masahiro Yamada and Nicolas Schier.
I ended up with COLOR_YELLOW, as it seems to look comparatively dim
with mutliple light and dark color themes in Chromium hterm and
gnome-terminal.

diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h
index a501abf9fa31..2bba0c406038 100644
--- a/scripts/kconfig/lxdialog/dialog.h
+++ b/scripts/kconfig/lxdialog/dialog.h
@@ -100,6 +100,8 @@ struct dialog_info {
struct dialog_color menubox_border;
struct dialog_color item;
struct dialog_color item_selected;
+ struct dialog_color item_hidden;
+ struct dialog_color item_hidden_selected;
struct dialog_color tag;
struct dialog_color tag_selected;
struct dialog_color tag_key;
@@ -128,6 +130,7 @@ void item_add_str(const char *fmt, ...);
void item_set_tag(char tag);
void item_set_data(void *p);
void item_set_selected(int val);
+void item_set_hidden(int val);
int item_activate_selected(void);
void *item_data(void);
char item_tag(void);
@@ -139,6 +142,7 @@ struct dialog_item {
char tag;
void *data; /* pointer to menu item - used by menubox+checklist */
int selected; /* Set to 1 by dialog_*() function if selected. */
+ int hidden; /* Set to 1 if hidden. */
};

/* list of lialog_items */
@@ -157,6 +161,7 @@ int item_n(void);
const char *item_str(void);
int item_is_selected(void);
int item_is_tag(char tag);
+int item_is_hidden(void);
#define item_foreach() \
for (item_cur = item_head ? item_head: item_cur; \
item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index 0e333284e947..3bff89eb8cdf 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -51,9 +51,9 @@ static int menu_width, item_x;
* Print menu item
*/
static void do_print_item(WINDOW * win, const char *item, int line_y,
- int selected, int hotkey)
+ int selected, int hotkey, int hidden)
{
- int j;
+ int j, attrs;
char *menu_item = malloc(menu_width + 1);

strncpy(menu_item, item, menu_width - item_x);
@@ -64,7 +64,11 @@ static void do_print_item(WINDOW * win, const char *item, int line_y,
wattrset(win, dlg.menubox.atr);
wmove(win, line_y, 0);
wclrtoeol(win);
- wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
+ if (hidden)
+ attrs = selected ? dlg.item_hidden_selected.atr : dlg.item_hidden.atr;
+ else
+ attrs = selected ? dlg.item_selected.atr : dlg.item.atr;
+ wattrset(win, attrs);
mvwaddstr(win, line_y, item_x, menu_item);
if (hotkey) {
wattrset(win, selected ? dlg.tag_key_selected.atr
@@ -81,7 +85,7 @@ static void do_print_item(WINDOW * win, const char *item, int line_y,
#define print_item(index, choice, selected) \
do { \
item_set(index); \
- do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \
+ do_print_item(menu, item_str(), choice, selected, !item_is_tag(':'), item_is_hidden()); \
} while (0)

/*
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index 3f78fb265136..161224dd6fb5 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -38,6 +38,8 @@ static void set_mono_theme(void)
dlg.menubox_border.atr = A_NORMAL;
dlg.item.atr = A_NORMAL;
dlg.item_selected.atr = A_REVERSE;
+ dlg.item_hidden.atr = A_NORMAL | A_DIM;
+ dlg.item_hidden_selected.atr = A_REVERSE | A_DIM;
dlg.tag.atr = A_BOLD;
dlg.tag_selected.atr = A_REVERSE;
dlg.tag_key.atr = A_BOLD;
@@ -78,6 +80,8 @@ static void set_classic_theme(void)
DLG_COLOR(menubox_border, COLOR_WHITE, COLOR_WHITE, true);
DLG_COLOR(item, COLOR_BLACK, COLOR_WHITE, false);
DLG_COLOR(item_selected, COLOR_WHITE, COLOR_BLUE, true);
+ DLG_COLOR(item_hidden, COLOR_YELLOW, COLOR_WHITE, false);
+ DLG_COLOR(item_hidden_selected, COLOR_WHITE, COLOR_BLUE, true);
DLG_COLOR(tag, COLOR_YELLOW, COLOR_WHITE, true);
DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_BLUE, true);
DLG_COLOR(tag_key, COLOR_YELLOW, COLOR_WHITE, true);
@@ -118,6 +122,9 @@ static void set_blackbg_theme(void)
DLG_COLOR(item, COLOR_WHITE, COLOR_BLACK, false);
DLG_COLOR(item_selected, COLOR_WHITE, COLOR_RED, false);

+ DLG_COLOR(item_hidden, COLOR_YELLOW, COLOR_BLACK, false);
+ DLG_COLOR(item_hidden_selected, COLOR_YELLOW, COLOR_RED, false);
+
DLG_COLOR(tag, COLOR_RED, COLOR_BLACK, false);
DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_RED, true);
DLG_COLOR(tag_key, COLOR_RED, COLOR_BLACK, false);
@@ -198,6 +205,8 @@ static void init_dialog_colors(void)
init_one_color(&dlg.menubox_border);
init_one_color(&dlg.item);
init_one_color(&dlg.item_selected);
+ init_one_color(&dlg.item_hidden);
+ init_one_color(&dlg.item_hidden_selected);
init_one_color(&dlg.tag);
init_one_color(&dlg.tag_selected);
init_one_color(&dlg.tag_key);
@@ -635,6 +644,11 @@ void item_set_selected(int val)
item_cur->node.selected = val;
}

+void item_set_hidden(int val)
+{
+ item_cur->node.hidden = val;
+}
+
int item_activate_selected(void)
{
item_foreach()
@@ -698,3 +712,8 @@ int item_is_tag(char tag)
{
return (item_cur->node.tag == tag);
}
+
+int item_is_hidden(void)
+{
+ return (item_cur->node.hidden != 0);
+}
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index f4bb391d50cf..b7e08ec98717 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -488,6 +488,8 @@ static void build_conf(struct menu *menu)
menu_is_empty(menu) ? "----" : "--->");
item_set_tag('m');
item_set_data(menu);
+ if (!visible)
+ item_set_hidden(TRUE);
if (single_menu_mode && menu->data)
goto conf_childs;
return;
@@ -497,6 +499,8 @@ static void build_conf(struct menu *menu)
item_make(" %*c*** %s ***", indent + 1, ' ', prompt);
item_set_tag(':');
item_set_data(menu);
+ if (!visible)
+ item_set_hidden(TRUE);
}
break;
default:
@@ -505,6 +509,8 @@ static void build_conf(struct menu *menu)
item_make("---%*c%s", indent + 1, ' ', prompt);
item_set_tag(':');
item_set_data(menu);
+ if (!visible)
+ item_set_hidden(TRUE);
}
}
} else
@@ -540,10 +546,14 @@ static void build_conf(struct menu *menu)
}
item_set_tag('t');
item_set_data(menu);
+ if (!visible)
+ item_set_hidden(TRUE);
} else {
item_make(" ");
item_set_tag(def_menu ? 't' : ':');
item_set_data(menu);
+ if (!visible)
+ item_set_hidden(TRUE);
}

item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
@@ -564,6 +574,8 @@ static void build_conf(struct menu *menu)
item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu));
item_set_tag(':');
item_set_data(menu);
+ if (!visible)
+ item_set_hidden(TRUE);
goto conf_childs;
}
child_count++;
@@ -581,6 +593,8 @@ static void build_conf(struct menu *menu)
item_make("-%c-", val == no ? ' ' : '*');
item_set_tag('t');
item_set_data(menu);
+ if (!visible)
+ item_set_hidden(TRUE);
break;
case S_TRISTATE:
switch (val) {
@@ -597,6 +611,8 @@ static void build_conf(struct menu *menu)
item_make("-%c-", ch);
item_set_tag('t');
item_set_data(menu);
+ if (!visible)
+ item_set_hidden(TRUE);
break;
default:
tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
@@ -609,6 +625,8 @@ static void build_conf(struct menu *menu)
"" : " (NEW)");
item_set_tag('s');
item_set_data(menu);
+ if (!visible)
+ item_set_hidden(TRUE);
goto conf_childs;
}
}
--
2.39.2



2024-02-28 07:45:14

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH v2] kconfig: menuconfig: Make hidden options show with different color

On Wed, Feb 28, 2024 at 03:00:05PM +0900, Tomasz Figa wrote:
> When hidden options are toggled on (using 'z'), the number of options
> on the screen can be overwhelming and may make it hard to distinguish
> between available and hidden ones. Make them easier to distinguish by
> displaying the hidden one with a different color (COLOR_YELLOW for color
> themes and A_DIM for mono).
>
> Signed-off-by: Tomasz Figa <[email protected]>
> ---
> scripts/kconfig/lxdialog/dialog.h | 5 +++++
> scripts/kconfig/lxdialog/menubox.c | 12 ++++++++----
> scripts/kconfig/lxdialog/util.c | 19 +++++++++++++++++++
> scripts/kconfig/mconf.c | 18 ++++++++++++++++++
> 4 files changed, 50 insertions(+), 4 deletions(-)
>
> Changes from v1:
> (https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/)
> * Replaced A_DIM for color themes with COLOR_YELLOW, because the former
> has no effect to black text on some commonly used terminals, e.g.
> gnome-terminal, foot. Reported by Masahiro Yamada and Nicolas Schier.
> I ended up with COLOR_YELLOW, as it seems to look comparatively dim
> with mutliple light and dark color themes in Chromium hterm and
> gnome-terminal.

Thanks, output looks good to me on my console as well as on all my
terminal emulators and in all themes.

Tested-by: Nicolas Schier <[email protected]>

2024-02-29 01:59:22

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH v2] kconfig: menuconfig: Make hidden options show with different color

On Wed, Feb 28, 2024 at 3:00 PM Tomasz Figa <[email protected]> wrote:
>
> When hidden options are toggled on (using 'z'), the number of options
> on the screen can be overwhelming and may make it hard to distinguish
> between available and hidden ones. Make them easier to distinguish by
> displaying the hidden one with a different color (COLOR_YELLOW for color
> themes and A_DIM for mono).
>
> Signed-off-by: Tomasz Figa <[email protected]>
> ---


> diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
> index 3f78fb265136..161224dd6fb5 100644
> --- a/scripts/kconfig/lxdialog/util.c
> +++ b/scripts/kconfig/lxdialog/util.c
> @@ -38,6 +38,8 @@ static void set_mono_theme(void)
> dlg.menubox_border.atr = A_NORMAL;
> dlg.item.atr = A_NORMAL;
> dlg.item_selected.atr = A_REVERSE;
> + dlg.item_hidden.atr = A_NORMAL | A_DIM;


Nit.


(A_NORMAL | A_DIM) should be A_DIM.


A_NORMAL is zero.

Other A_* attributes are bit flags that can be OR'ed.




--
Best Regards
Masahiro Yamada

2024-02-29 05:41:24

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH v2] kconfig: menuconfig: Make hidden options show with different color

Hi,

On 2/27/24 22:00, Tomasz Figa wrote:
> When hidden options are toggled on (using 'z'), the number of options
> on the screen can be overwhelming and may make it hard to distinguish
> between available and hidden ones. Make them easier to distinguish by
> displaying the hidden one with a different color (COLOR_YELLOW for color
> themes and A_DIM for mono).


> Signed-off-by: Tomasz Figa <[email protected]>
> ---
> scripts/kconfig/lxdialog/dialog.h | 5 +++++
> scripts/kconfig/lxdialog/menubox.c | 12 ++++++++----
> scripts/kconfig/lxdialog/util.c | 19 +++++++++++++++++++
> scripts/kconfig/mconf.c | 18 ++++++++++++++++++
> 4 files changed, 50 insertions(+), 4 deletions(-)


> Changes from v1:
> (https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/)
> * Replaced A_DIM for color themes with COLOR_YELLOW, because the former
> has no effect to black text on some commonly used terminals, e.g.
> gnome-terminal, foot. Reported by Masahiro Yamada and Nicolas Schier.
> I ended up with COLOR_YELLOW, as it seems to look comparatively dim
> with mutliple light and dark color themes in Chromium hterm and
> gnome-terminal.

I guess COLOR_YELLOW is a relative thing, i.e., it depends on the term's
current color scheme in my testing.

With rxvt (with a beige/khaki background), I do see yellow.

With xfce4-terminal (with amber/orange foreground on black background,
i.e., my default from days of amber monochrome displays ;), the "yellow"
comes out as a faded/washed out/dim orange. But still readable.

Anyway, this looks useful to me.

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

thanks.
--
#Randy

2024-03-05 07:50:02

by Tomasz Figa

[permalink] [raw]
Subject: Re: [PATCH v2] kconfig: menuconfig: Make hidden options show with different color

On Thu, Feb 29, 2024 at 2:40 PM Randy Dunlap <[email protected]> wrote:
>
> Hi,
>
> On 2/27/24 22:00, Tomasz Figa wrote:
> > When hidden options are toggled on (using 'z'), the number of options
> > on the screen can be overwhelming and may make it hard to distinguish
> > between available and hidden ones. Make them easier to distinguish by
> > displaying the hidden one with a different color (COLOR_YELLOW for color
> > themes and A_DIM for mono).
>
>
> > Signed-off-by: Tomasz Figa <[email protected]>
> > ---
> > scripts/kconfig/lxdialog/dialog.h | 5 +++++
> > scripts/kconfig/lxdialog/menubox.c | 12 ++++++++----
> > scripts/kconfig/lxdialog/util.c | 19 +++++++++++++++++++
> > scripts/kconfig/mconf.c | 18 ++++++++++++++++++
> > 4 files changed, 50 insertions(+), 4 deletions(-)
>
>
> > Changes from v1:
> > (https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/)
> > * Replaced A_DIM for color themes with COLOR_YELLOW, because the former
> > has no effect to black text on some commonly used terminals, e.g.
> > gnome-terminal, foot. Reported by Masahiro Yamada and Nicolas Schier.
> > I ended up with COLOR_YELLOW, as it seems to look comparatively dim
> > with mutliple light and dark color themes in Chromium hterm and
> > gnome-terminal.
>
> I guess COLOR_YELLOW is a relative thing, i.e., it depends on the term's
> current color scheme in my testing.

Yeah, it's kind of on the edge of being relatively neutral, i.e. not
standing out much more than the visible options, but I couldn't really
find anything that would work better for the standard 16-color mode.
An alternative would be to implement support for the 256-color mode,
but that would likely require quite a lot of changes in the existing
code (and I'm not very familiar with how to do it in ncurses...).

>
> With rxvt (with a beige/khaki background), I do see yellow.
>
> With xfce4-terminal (with amber/orange foreground on black background,
> i.e., my default from days of amber monochrome displays ;), the "yellow"
> comes out as a faded/washed out/dim orange. But still readable.
>
> Anyway, this looks useful to me.
>
> Acked-by: Randy Dunlap <[email protected]>
> Tested-by: Randy Dunlap <[email protected]>

Thanks a lot!

Best regards,
Tomasz