From ecada8f25e96cd90fce865356a13604a3d97ce2a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 16 Jul 2019 17:17:29 +0200 Subject: [PATCH] firstboot: only list all options on demand The user most likely knows the name of their locale/keymap/whatever, and paging through multiple pages of output has little benefit. The header that was printed before is now not printed anymore. But now it's obvious from the context what we are printing, so we don't need to print the header. --- src/firstboot/firstboot.c | 46 ++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index dca3a25e34a..1de5d122231 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -164,7 +164,7 @@ static int show_menu(char **x, unsigned n_columns, unsigned width, unsigned perc return 0; } -static int prompt_loop(const char *text, char **l, bool (*is_valid)(const char *name), char **ret) { +static int prompt_loop(const char *text, char **l, unsigned percentage, bool (*is_valid)(const char *name), char **ret) { int r; assert(text); @@ -175,7 +175,8 @@ static int prompt_loop(const char *text, char **l, bool (*is_valid)(const char * _cleanup_free_ char *p = NULL; unsigned u; - r = ask_string(&p, "%s %s (empty to skip): ", special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET), text); + r = ask_string(&p, "%s %s (empty to skip, \"list\" to list options): ", + special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET), text); if (r < 0) return log_error_errno(r, "Failed to query user: %m"); @@ -184,6 +185,15 @@ static int prompt_loop(const char *text, char **l, bool (*is_valid)(const char * return 0; } + if (streq(p, "list")) { + r = show_menu(l, 3, 22, percentage); + if (r < 0) + return r; + + putchar('\n'); + continue; + }; + r = safe_atou(p, &u); if (r >= 0) { if (u <= 0 || u > strv_length(l)) { @@ -239,21 +249,16 @@ static int prompt_locale(void) { } else { print_welcome(); - printf("\nAvailable Locales:\n\n"); - r = show_menu(locales, 3, 22, 60); - if (r < 0) - return r; - - putchar('\n'); - - r = prompt_loop("Please enter system locale name or number", locales, locale_is_valid, &arg_locale); + r = prompt_loop("Please enter system locale name or number", + locales, 60, locale_is_valid, &arg_locale); if (r < 0) return r; if (isempty(arg_locale)) return 0; - r = prompt_loop("Please enter system message locale name or number", locales, locale_is_valid, &arg_locale_messages); + r = prompt_loop("Please enter system message locale name or number", + locales, 60, locale_is_valid, &arg_locale_messages); if (r < 0) return r; @@ -329,15 +334,8 @@ static int prompt_keymap(void) { print_welcome(); - printf("\nAvailable keymaps:\n\n"); - r = show_menu(kmaps, 3, 22, 60); - if (r < 0) - return r; - - putchar('\n'); - return prompt_loop("Please enter system keymap name or number", - kmaps, keymap_is_valid, &arg_keymap); + kmaps, 60, keymap_is_valid, &arg_keymap); } static int process_keymap(void) { @@ -405,14 +403,8 @@ static int prompt_timezone(void) { print_welcome(); - printf("\nAvailable Time Zones:\n\n"); - r = show_menu(zones, 3, 22, 30); - if (r < 0) - return r; - - putchar('\n'); - - r = prompt_loop("Please enter timezone name or number", zones, timezone_is_valid_log_error, &arg_timezone); + r = prompt_loop("Please enter timezone name or number", + zones, 30, timezone_is_valid_log_error, &arg_timezone); if (r < 0) return r; -- 2.47.3