From 9f5c5e09b4c2cc35960f401dc2732a0476440bb6 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Thu, 8 Jul 2021 16:57:40 +0200 Subject: [PATCH] menu: Support entry comments --- stage23/lib/config.c | 17 +++++++++++------ stage23/lib/config.h | 1 + stage23/menu.c | 8 +++++++- test/limine.cfg | 8 ++++++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/stage23/lib/config.c b/stage23/lib/config.c index 43e09c62..0eccabd6 100644 --- a/stage23/lib/config.c +++ b/stage23/lib/config.c @@ -105,15 +105,20 @@ static struct menu_entry *create_menu_tree(struct menu_entry *parent, strcpy(entry->name, name + current_depth + default_expanded); entry->parent = parent; + size_t entry_size; + char *config_entry = config_get_entry(&entry_size, i); + entry->body = ext_mem_alloc(entry_size + 1); + memcpy(entry->body, config_entry, entry_size); + entry->body[entry_size] = 0; + if (is_directory(name, 64, current_depth, i)) { entry->sub = create_menu_tree(entry, current_depth + 1, i + 1); entry->expanded = default_expanded; - } else { - size_t entry_size; - char *config_entry = config_get_entry(&entry_size, i); - entry->body = ext_mem_alloc(entry_size + 1); - memcpy(entry->body, config_entry, entry_size); - entry->body[entry_size] = 0; + } + + char *comment = config_get_value(entry->body, 0, "COMMENT"); + if (comment != NULL) { + entry->comment = comment; } if (prev != NULL) diff --git a/stage23/lib/config.h b/stage23/lib/config.h index 711d191b..f9cea928 100644 --- a/stage23/lib/config.h +++ b/stage23/lib/config.h @@ -9,6 +9,7 @@ extern bool config_ready; struct menu_entry { char name[64]; + char *comment; struct menu_entry *parent; struct menu_entry *sub; bool expanded; diff --git a/stage23/menu.c b/stage23/menu.c index 813545cf..f7cb0b9b 100644 --- a/stage23/menu.c +++ b/stage23/menu.c @@ -104,6 +104,7 @@ static const char *VALID_KEYS[] = { "DRIVE", "PARTITION", "IMAGE_PATH", + "COMMENT", NULL }; @@ -593,6 +594,7 @@ refresh: set_cursor_pos(x, y); } + if (selected_menu_entry->sub != NULL) skip_timeout = true; @@ -606,7 +608,7 @@ refresh: term_double_buffer_flush(); if ((c = pit_sleep_and_quit_on_keypress(1))) { skip_timeout = true; - print("\e[2K\r"); + print("\e[2K"); term_double_buffer_flush(); goto timeout_aborted; } @@ -614,6 +616,10 @@ refresh: goto autoboot; } + set_cursor_pos(0, term_rows - 1); + if (selected_menu_entry->comment != NULL) + print("\e[32m%s", selected_menu_entry->comment); + term_double_buffer_flush(); for (;;) { diff --git a/test/limine.cfg b/test/limine.cfg index 6900a032..8ae4363b 100644 --- a/test/limine.cfg +++ b/test/limine.cfg @@ -12,6 +12,8 @@ BACKDROP_COLOUR=008080 :Stivale2 Test +COMMENT=Test of the stivale2 boot protocol. + PROTOCOL=stivale2 RESOLUTION=800x600 KERNEL_PATH=boot:///boot/test.elf @@ -22,13 +24,19 @@ MODULE_STRING=yooooo :EFI Chainloading +COMMENT=Test EFI image chainloading. + PROTOCOL=chainload IMAGE_PATH=boot:///EFI/BOOT/BOOTX64.EFI :+Legacy +COMMENT=Contains legacy entries. + ::Stivale Test +COMMENT=Stivale1 test. + PROTOCOL=stivale KERNEL_PATH=boot:///boot/test.elf KERNEL_CMDLINE=Hi! This is an example!