Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68E9EC38A2D for ; Mon, 24 Oct 2022 05:40:33 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2821184E95; Mon, 24 Oct 2022 07:40:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="Nld8Xmu5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1987D84F1A; Mon, 24 Oct 2022 07:40:29 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 31B4784E95 for ; Mon, 24 Oct 2022 07:40:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666590024; bh=9NI398wgRD/cO0LHVQQvj5VKncDKC32Y1wFRoAC+5Wg=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=Nld8Xmu5aXiiqr+OuSP3a5UmiNwoAxxoK6+sVMS4eUjxAXRuKQr3aKpEEZ0o8lxOj zWPm5jtYhdfkC5VZCwOTPEuS1/2nOFrkFMZzkr0xQW553C4rxbKwOZPSvAK6tzesXJ Fe5XXIGEtaRgZWt8Z5X/UkTjLHA5qQb0YYIhbu6I= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.117.42] ([46.114.32.55]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MrhQC-1pPSHT47a0-00ndSY; Mon, 24 Oct 2022 07:40:24 +0200 Message-ID: Date: Mon, 24 Oct 2022 07:40:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v4 3/7] eficonfig: add direct menu entry access mode To: Masahisa Kojima Cc: Ilias Apalodimas , Simon Glass , Takahiro Akashi , Stefan Roese , u-boot@lists.denx.de References: <20221024044804.3351-1-masahisa.kojima@linaro.org> <20221024044804.3351-4-masahisa.kojima@linaro.org> Content-Language: en-US From: Heinrich Schuchardt In-Reply-To: <20221024044804.3351-4-masahisa.kojima@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:Pr6UccEAGs7cR0MwGe7ROGHanJqkdqscYLFpOWYxyQYGCe71neA Ewm/lEn90JOQGhZLUsroBcsnNbIBMf+HjglXIxtJQRSY3uDfcQOwYPT6tYHeWy+ew5PsZvt VIN1hVhSSYPy/0hkK9+dRhN/AUWu4qGWwhTDSnWgFc2v/Bzo7V5JXtIhpMHHeMVQbenc6i4 +d2epmdT22YaKqwy9OGVw== X-UI-Out-Filterresults: notjunk:1;V03:K0:kM5KbPcDVeA=:YEuWZP8icy5b76nz1PUWm3 xxYCsxgigmAw6lvzWJ1KsIPHgpEgBnD/JcWzapTPrvVd1hAVApne/es1xQbzjT+LOjk54PjNv Ib3lX5cZ8FxWP7xDdYt3T5NifyTjyJNXqmAPZ9poz40oqDHqrKjHbd5HpZscA1CsJXyqIZx/r SUCG5intppv114BStkGwW6JP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4f/QvXNl8G0lABMpR5Hy9MusFlPDC38IpNybk6RNgSS8AIHQ9szzbNQVjAwH3fKqWveC Kl1q9tY9CDpC3I+zLazPpTAhqKaeZftAaXDfyd9W8tbf17q/mGyaJyBvUyz78bivS2nMq/Pbs SM3EwS4rqVC9fGu3uX0cy57be8zNPKNTF+ajZoryeRtNXRNd59wOrIvLU3Y/D0JZTBvk5LsnS 1NACYrIiYpvx+o7DDqKHs6uU+g8OcWlkE56NhvciMX7tkL5dqnjrAphkKTcV+NNXKtneuLRYR 1ZzvOxYKyJeQeooJpU9Fvr1WgN45wOzhtbDQeHS3CLnk/ X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 10/24/22 06:48, Masahisa Kojima wrote: > This commit adds the direct menu entry access mode. > User can select the menu entry by '&' key followed by > the menu title name. > > User input is read in UTF-16, then UTF-16 string is converted > into UTF-8 internally because string comparison relies on strncasecmp(). > There is no equivalent string comparison function for UTF-16. > > Signed-off-by: Masahisa Kojima > --- > Newly added in v4 > > cmd/eficonfig.c | 120 ++++++++++++++++++++++++++++++++++++++++++- > common/menu.c | 3 ++ > include/efi_config.h | 3 ++ > include/menu.h | 1 + > 4 files changed, 126 insertions(+), 1 deletion(-) > > diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c > index 0cb0770ac3..56d9268f9f 100644 > --- a/cmd/eficonfig.c > +++ b/cmd/eficonfig.c > @@ -22,6 +22,7 @@ > > static struct efi_simple_text_input_protocol *cin; > > +#define EFICONFIG_ACCESSOR_STR_MAX 16 > #define EFICONFIG_DESCRIPTION_MAX 32 > #define EFICONFIG_OPTIONAL_DATA_MAX 64 > > @@ -155,7 +156,28 @@ static void eficonfig_print_entry(void *data) > if (reverse) > puts(ANSI_COLOR_REVERSE); > > - printf("%s", entry->title); > + if (reverse && entry->efi_menu->direct_access_mode) { > + size_t len =3D u16_strlen(entry->efi_menu->accessor_str); > + char *accessor_str, *p; > + > + accessor_str =3D calloc(1, utf16_utf8_strlen(entry->efi_menu->accesso= r_str) + 1); > + if (!accessor_str) { > + printf("%s", entry->title); > + return; > + } > + p =3D accessor_str; > + utf16_utf8_strncpy(&p, entry->efi_menu->accessor_str, EFICONFIG_ACCES= SOR_STR_MAX); > + len =3D strlen(accessor_str); > + if (!strncasecmp(accessor_str, entry->title, len)) { > + printf("%.*s" ANSI_COLOR_RESET "%s", (int)len, entry->title, > + &entry->title[len]); > + } else { > + printf("%s", entry->title); > + } > + free(accessor_str); > + } else { > + printf("%s", entry->title); > + } > > if (reverse) > puts(ANSI_COLOR_RESET); > @@ -182,6 +204,83 @@ static void eficonfig_display_statusline(struct men= u *m) > entry->efi_menu->count + 6, 1, entry->efi_menu->count + 7, 1); > } > > +/** > + * eficonfig_handle_direct_accessor() - handle direct access user input > + * > + * @efi_menu: pointer to the efimenu structure > + * Return: key string to identify the selected entry > + */ > +static char *eficonfig_handle_direct_accessor(struct efimenu *efi_menu) > +{ > + efi_status_t ret; > + char *accessor_str, *p; > + struct efi_input_key key; > + struct list_head *pos, *n; > + struct eficonfig_entry *entry; > + static int len; > + > + /* Read user input */ > + do { > + ret =3D EFI_CALL(cin->read_key_stroke(cin, &key)); > + mdelay(10); > + } while (ret =3D=3D EFI_NOT_READY); > + > + /* If user presses Ctrl+C or ESC, exit direct access mode */ > + if (key.unicode_char =3D=3D 0x3 || key.scan_code =3D=3D 23) > + goto out; > + > + /* If user presses ENTER, exit direct access mode and return the activ= e entry */ > + if (key.unicode_char =3D=3D u'\r') { > + list_for_each_safe(pos, n, &efi_menu->list) { > + entry =3D list_entry(pos, struct eficonfig_entry, list); > + if (entry->num =3D=3D efi_menu->active) { > + efi_menu->direct_access_mode =3D false; > + memset(efi_menu->accessor_str, 0, > + EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); > + return entry->key; > + } > + } > + > + /* no matching entry */ > + goto out; > + } > + > + /* Ignore other control code and efi scan code */ > + if (key.unicode_char < 0x20 || key.scan_code !=3D 0) > + return NULL; > + > + len =3D u16_strlen(efi_menu->accessor_str); > + if (len < EFICONFIG_ACCESSOR_STR_MAX - 1) > + efi_menu->accessor_str[len] =3D key.unicode_char; > + > + accessor_str =3D calloc(1, utf16_utf8_strlen(efi_menu->accessor_str) += 1); > + if (!accessor_str) > + return NULL; > + > + p =3D accessor_str; > + utf16_utf8_strncpy(&p, efi_menu->accessor_str, EFICONFIG_ACCESSOR_STR_= MAX); > + > + list_for_each_safe(pos, n, &efi_menu->list) { > + entry =3D list_entry(pos, struct eficonfig_entry, list); > + if (!strncasecmp(accessor_str, entry->title, strlen(accessor_str))) { > + efi_menu->active =3D entry->num; > + free(accessor_str); > + return NULL; > + } > + } > + > + /* does not match any entries */ > + free(accessor_str); > + efi_menu->active =3D 0; > + return NULL; > + > +out: > + efi_menu->direct_access_mode =3D false; > + memset(efi_menu->accessor_str, 0, EFICONFIG_ACCESSOR_STR_MAX * sizeof(= u16)); > + efi_menu->active =3D 0; > + return NULL; > +} > + > /** > * eficonfig_choice_entry() - user key input handler > * > @@ -196,6 +295,9 @@ static char *eficonfig_choice_entry(void *data) > enum bootmenu_key key =3D KEY_NONE; > struct efimenu *efi_menu =3D data; > > + if (efi_menu->direct_access_mode) > + return eficonfig_handle_direct_accessor(efi_menu); > + > while (1) { > bootmenu_loop((struct bootmenu_data *)efi_menu, &key, &esc); > > @@ -221,6 +323,10 @@ static char *eficonfig_choice_entry(void *data) > /* Quit by choosing the last entry */ > entry =3D list_last_entry(&efi_menu->list, struct eficonfig_entry, = list); > return entry->key; > + case KEY_AMPERSAND: > + memset(efi_menu->accessor_str, 0, EFICONFIG_ACCESSOR_STR_MAX * sizeo= f(u16)); > + efi_menu->direct_access_mode =3D true; > + return NULL; > default: > /* Pressed key is not valid, no need to regenerate the menu */ > break; > @@ -248,6 +354,7 @@ void eficonfig_destroy(struct efimenu *efi_menu) > free(entry); > } > free(efi_menu->menu_header); > + free(efi_menu->accessor_str); > free(efi_menu); > } > > @@ -385,6 +492,9 @@ efi_status_t eficonfig_process_common(struct efimenu= *efi_menu, char *menu_heade > if (!efi_menu->menu_header) > return EFI_OUT_OF_RESOURCES; > } > + efi_menu->accessor_str =3D calloc(1, EFICONFIG_ACCESSOR_STR_MAX * size= of(u16)); > + if (!efi_menu->accessor_str) > + return EFI_OUT_OF_RESOURCES; > > menu =3D menu_create(NULL, 0, 1, eficonfig_display_statusline, > eficonfig_print_entry, eficonfig_choice_entry, > @@ -1866,6 +1976,11 @@ static efi_status_t eficonfig_choice_change_boot_= order(struct efimenu *efi_menu) > enum bootmenu_key key =3D KEY_NONE; > struct eficonfig_boot_order *entry; > > + if (efi_menu->direct_access_mode) { > + eficonfig_handle_direct_accessor(efi_menu); > + return EFI_NOT_READY; > + } > + > while (1) { > bootmenu_loop(NULL, &key, &esc); > > @@ -1931,6 +2046,9 @@ static efi_status_t eficonfig_choice_change_boot_o= rder(struct efimenu *efi_menu) > break; > case KEY_QUIT: > return EFI_ABORTED; > + case KEY_AMPERSAND: > + efi_menu->direct_access_mode =3D true; > + return EFI_NOT_READY; > default: > /* Pressed key is not valid, no need to regenerate the menu */ > break; > diff --git a/common/menu.c b/common/menu.c > index 8fe00965c0..6ea9f5c9b8 100644 > --- a/common/menu.c > +++ b/common/menu.c > @@ -557,4 +557,7 @@ void bootmenu_loop(struct bootmenu_data *menu, > > if (c =3D=3D ' ') > *key =3D KEY_SPACE; > + > + if (c =3D=3D '&') > + *key =3D KEY_AMPERSAND; I am not really happy with how U-Boot menus work. I think there should be one function to which you pass the menu entries and you get back the index of the chosen entry (or some error code if ESC for pressed). My idea about "ampersand" was: You pass a list of strings to the menu function like: &Open &Close E&xit The displayed menu would highlight the access key in a different color, e.g. white instead of grey. *O*pen *C*lose E*x*it The user can navigate with either UP, Down and press Enter then you will get back the chosen entry. Or the user presses 'o', 'c', or 'x' and you will get back the index of the respective menu entry. The user would never use the '&' key. Best regards Heinrich > } > diff --git a/include/efi_config.h b/include/efi_config.h > index 86bc801211..1b84e2d579 100644 > --- a/include/efi_config.h > +++ b/include/efi_config.h > @@ -45,6 +45,7 @@ struct eficonfig_entry { > * @active: active menu entry index > * @count: total count of menu entry > * @menu_header: menu header string > + * @accessor_str: pointer to the accessor string for entry shortcut > * @list: menu entry list structure > */ > struct efimenu { > @@ -52,6 +53,8 @@ struct efimenu { > int active; > int count; > char *menu_header; > + bool direct_access_mode; > + u16 *accessor_str; > struct list_head list; > }; > > diff --git a/include/menu.h b/include/menu.h > index 702aacb170..03bf8dc4f5 100644 > --- a/include/menu.h > +++ b/include/menu.h > @@ -51,6 +51,7 @@ enum bootmenu_key { > KEY_PLUS, > KEY_MINUS, > KEY_SPACE, > + KEY_AMPERSAND, > }; > > void bootmenu_autoboot_loop(struct bootmenu_data *menu,