summaryrefslogtreecommitdiff
path: root/src/firstboot/firstboot.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-16 17:17:29 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-17 12:07:19 +0200
commitecada8f25e96cd90fce865356a13604a3d97ce2a (patch)
tree854f5cc4295f677ef4f3830984d5d6aa183ca2e4 /src/firstboot/firstboot.c
parentbfbf5f7408b3ded4f50012184d408f4395a577ca (diff)
downloadsystemd-ecada8f25e96cd90fce865356a13604a3d97ce2a.tar.gz
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.
Diffstat (limited to 'src/firstboot/firstboot.c')
-rw-r--r--src/firstboot/firstboot.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index dca3a25e34..1de5d12223 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;