Skip to content

Commit 84ef9c3

Browse files
committed
align the boot menu closer to systemd-boot's.
1) space no longer boots the selected entry. 2) there is now a brief delay that allows the user to bring up the boot menu via (i.a.) space. 3) a-zA-Z not bound to existing commands now allow cycling through entries whose names start with the pressed letter. resolves #554
1 parent 8cc8588 commit 84ef9c3

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

CONFIG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ Miscellaneous:
7676

7777
* `timeout` - Specifies the timeout in seconds before the first *entry* is
7878
automatically booted. If set to `no`, disable automatic boot. If set to `0`,
79-
boots default entry instantly (see `default_entry` option).
79+
boot the default entry (see `default_entry` option) after a brief (~1 second)
80+
window during which pressing any key reveals the menu. This window matches
81+
the systemd-boot behaviour of allowing the user to hold a key (space is a
82+
good choice) to bring up the menu at zero timeout.
8083
* `quiet` - If set to `yes`, enable quiet mode, where all screen output except
8184
panics and important warnings is suppressed. If `timeout` is not 0, the
8285
`timeout` still occurs, and pressing any key during the timeout will reveal

common/menu.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,8 +1326,13 @@ noreturn void _menu(bool first_run) {
13261326
quiet = false;
13271327
print("Default entry is not valid or directory, booting to menu.\n");
13281328
skip_timeout = true;
1329-
} else {
1329+
} else if (pit_sleep_and_quit_on_keypress(1) == 0) {
13301330
goto autoboot;
1331+
} else {
1332+
/* systemd-boot-esque: key pressed in the brief boot window; reveal the
1333+
menu instead of booting the default entry. */
1334+
skip_timeout = true;
1335+
quiet = false;
13311336
}
13321337
}
13331338

@@ -1581,7 +1586,6 @@ noreturn void _menu(bool first_run) {
15811586
goto refresh;
15821587
case GETCHAR_CURSOR_RIGHT:
15831588
case '\n':
1584-
case ' ':
15851589
autoboot:
15861590
if (max_entries == 0) {
15871591
break;
@@ -1659,6 +1663,37 @@ noreturn void _menu(bool first_run) {
16591663
}
16601664
break;
16611665
}
1666+
default: {
1667+
/* Cycle the selection to the next visible entry whose name starts
1668+
with the pressed letter */
1669+
if (max_entries == 0)
1670+
break;
1671+
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1672+
break;
1673+
char target = (char)c;
1674+
if (target >= 'A' && target <= 'Z') {
1675+
target = (char)(target - 'A' + 'a');
1676+
}
1677+
for (size_t step = 1; step <= max_entries; step++) {
1678+
size_t idx = (selected_entry + step) % max_entries;
1679+
struct menu_entry * candidate = NULL;
1680+
print_tree(0, 0, NULL, 0, 0, idx, menu_tree,
1681+
&candidate, NULL, NULL);
1682+
if (candidate == NULL || candidate->name == NULL
1683+
|| candidate->name[0] == 0) {
1684+
continue;
1685+
}
1686+
char first = candidate->name[0];
1687+
if (first >= 'A' && first <= 'Z') {
1688+
first = (char)(first - 'A' + 'a');
1689+
}
1690+
if (first == target) {
1691+
selected_entry = idx;
1692+
goto refresh;
1693+
}
1694+
}
1695+
break;
1696+
}
16621697
}
16631698
}
16641699
}

0 commit comments

Comments
 (0)