menu: Fix bug where variable may be used uninitialised, make DEFAULT_ENTRY 1-based, add 'no' setting for TIMEOUT

This commit is contained in:
mintsuki 2020-12-03 12:38:53 +01:00
parent fe022c49f5
commit 3ee1ee880b
6 changed files with 26 additions and 12 deletions

View File

@ -36,8 +36,8 @@ Some *local assignments* are shared between entries using any *protocol*, while
Some keys take *URIs* as values; these are described in the next section.
*Globally assignable* keys are:
* `TIMEOUT` - Specifies the timeout in seconds before the first *entry* is automatically booted.
* `DEFAULT_ENTRY` - 0-based entry index of the entry which will be automatically selected at startup. If unspecified, it is `0`.
* `TIMEOUT` - Specifies the timeout in seconds before the first *entry* is automatically booted. If set to `no`, disable automatic boot. If set to `0`, boots default entry instantly (see `DEFAULT_ENTRY` key).
* `DEFAULT_ENTRY` - 1-based entry index of the entry which will be automatically selected at startup. If unspecified, it is `1`.
* `GRAPHICS` - If set to `yes`, do use graphical VESA framebuffer for the boot menu, else use text mode.
* `MENU_RESOLUTION` - Specify screen resolution to be used by the Limine menu in the form `<width>x<height>`. This will *only* affect the menu, not any booted OS. If not specified, Limine will pick a resolution automatically. If the resolution is not available, Limine will pick another one automatically. Ignored if `GRAPHICS` is not `yes`.
* `THEME_COLOURS` - Specifies the colour palette used by the terminal (AARRGGBB). It is a `;` separated array of 8 colours: black, red, green, brown, blue, magenta, cyan, and gray, respectively. Ignored if `GRAPHICS` is not `yes`.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -194,8 +194,8 @@ refresh:
}
static int print_tree(int level, int base_index, int selected_entry,
struct menu_entry *current_entry,
struct menu_entry **selected_menu_entry) {
struct menu_entry *current_entry,
struct menu_entry **selected_menu_entry) {
int max_entries = 0;
for (;;) {
if (current_entry == NULL)
@ -239,23 +239,40 @@ static int print_tree(int level, int base_index, int selected_entry,
}
char *menu(char **cmdline) {
if (menu_tree == NULL)
panic("Config contains no valid entries.");
bool skip_timeout = false;
struct menu_entry *selected_menu_entry;
struct menu_entry *selected_menu_entry = NULL;
int selected_entry = 0;
char *default_entry = config_get_value(NULL, 0, "DEFAULT_ENTRY");
if (default_entry != NULL) {
selected_entry = strtoui(default_entry, NULL, 10);
if (selected_entry)
selected_entry--;
}
int timeout = 5;
char *timeout_config = config_get_value(NULL, 0, "TIMEOUT");
if (timeout_config != NULL) {
timeout = strtoui(timeout_config, NULL, 10);
if (!strcmp(timeout_config, "no"))
skip_timeout = true;
else
timeout = strtoui(timeout_config, NULL, 10);
}
if (!timeout)
goto autoboot;
if (!timeout) {
// Use print tree to load up selected_menu_entry and determine if the
// default entry is valid.
print_tree(0, 0, selected_entry, menu_tree, &selected_menu_entry);
if (selected_menu_entry == NULL || selected_menu_entry->sub != NULL) {
print("Default entry is not valid or directory, booting to menu.\n");
skip_timeout = true;
} else {
goto autoboot;
}
}
// If there is GRAPHICS config key and the value is "yes", enable graphics
char *graphics = config_get_value(NULL, 0, "GRAPHICS");
@ -321,9 +338,6 @@ char *menu(char **cmdline) {
disable_cursor();
if (menu_tree == NULL)
panic("Config contains no entries.");
term_double_buffer(true);
refresh:

View File

@ -1,4 +1,4 @@
DEFAULT_ENTRY=1
DEFAULT_ENTRY=2
TIMEOUT=3
GRAPHICS=yes
MENU_RESOLUTION=1024x768