menu: Add support for comments in entry editor

This commit is contained in:
mintsuki 2021-07-08 17:28:43 +02:00
parent 3270ce1bf8
commit 8636aa2f13
2 changed files with 12 additions and 6 deletions

View File

@ -15,6 +15,7 @@ not be shadowed by another potentially candidate config file.
## Structure of the config file
The Limine configuration file is comprised of *assignments* and *entries*.
Comments begin in '#'.
### Entries and sub-entries

View File

@ -20,6 +20,7 @@ static char *menu_branding = NULL;
#define TOK_EQUALS 1
#define TOK_VALUE 2
#define TOK_BADKEY 3
#define TOK_COMMENT 4
static size_t get_line_offset(size_t *displacement, size_t index, const char *buffer) {
size_t offset = 0;
@ -113,6 +114,8 @@ static bool invalid_syntax = false;
static int validate_line(const char *buffer) {
if (!validation_enabled) return TOK_KEY;
if (buffer[0] == '#')
return TOK_COMMENT;
char keybuf[64];
int i;
for (i = 0; buffer[i] && i < 64; i++) {
@ -282,12 +285,14 @@ refresh:
case TOK_EQUALS:
print("\e[32m%c\e[0m", buffer[i]);
break;
case TOK_VALUE:
print("\e[39m%c\e[0m", buffer[i]);
break;
case TOK_BADKEY:
print("\e[31m%c\e[0m", buffer[i]);
break;
case TOK_VALUE:
print("\e[39m%c\e[0m", buffer[i]);
break;
case TOK_BADKEY:
print("\e[31m%c\e[0m", buffer[i]);
break;
case TOK_COMMENT:
print("\e[33m%c\e[0m", buffer[i]);
}
} else {
print("%c", buffer[i]);