Merge pull request #154 from czapek1337/trunk

Several UX improvements around the console, menu and entry editor
This commit is contained in:
mint 2022-01-29 08:03:22 +01:00 committed by GitHub
commit ea4db246c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 8 deletions

View File

@ -13,6 +13,7 @@ static void console_help(void) {
print(
"Available commands:\n"
"exit -- Exit Limine console.\n"
"clear -- Clears the console.\n"
"editor -- Open an empty boot entry editor.\n"
"version -- Print version.\n"
"copyright -- Print copyright.\n"
@ -33,6 +34,8 @@ void console(void) {
console_help();
} else if (strcmp(prompt, "exit") == 0) {
break;
} else if (strcmp(prompt, "clear") == 0) {
print("\e[2J\e[H");
} else if (strcmp(prompt, "editor") == 0) {
char *new_entry = config_entry_editor("New Entry", "");
if (new_entry != NULL) {

View File

@ -2,6 +2,10 @@
#define __LIB__LIBC_H__
#include <stddef.h>
#include <stdbool.h>
bool isprint(int c);
bool isspace(int c);
int toupper(int c);
int tolower(int c);

View File

@ -4,6 +4,14 @@
#include <stdbool.h>
#include <lib/blib.h>
bool isprint(int c) {
return c >= ' ' && c <= '~';
}
bool isspace(int c) {
return (c >= '\t' && c <= 0xD) || c == ' ';
}
int toupper(int c) {
if (c >= 'a' && c <= 'z') {
return c - 0x20;

View File

@ -302,6 +302,9 @@ void readline(const char *orig_str, char *buf, size_t limit) {
cursor_back();
case GETCHAR_DELETE:;
size_t j;
if (buf[i] == 0) {
continue;
}
for (j = i; ; j++) {
buf[j] = buf[j+1];
if (!buf[j]) {
@ -316,8 +319,20 @@ void readline(const char *orig_str, char *buf, size_t limit) {
case '\n':
term_write((uintptr_t)"\n", 1);
goto out;
case GETCHAR_END:
for (size_t j = 0; j < strlen(buf) - i; j++) {
cursor_fwd();
}
i = strlen(buf);
continue;
case GETCHAR_HOME:
for (size_t j = 0; j < i; j++) {
cursor_back();
}
i = 0;
continue;
default: {
if (strlen(buf) < limit - 1) {
if (strlen(buf) < limit - 1 && isprint(c)) {
for (size_t j = strlen(buf); ; j--) {
buf[j+1] = buf[j];
if (j == i)

View File

@ -463,12 +463,14 @@ refresh:
return NULL;
default:
if (strlen(buffer) < EDITOR_MAX_BUFFER_SIZE - 1) {
for (size_t i = strlen(buffer); ; i--) {
buffer[i+1] = buffer[i];
if (i == cursor_offset)
break;
if (isprint(c) || c == '\n') {
for (size_t i = strlen(buffer); ; i--) {
buffer[i+1] = buffer[i];
if (i == cursor_offset)
break;
}
buffer[cursor_offset++] = c;
}
buffer[cursor_offset++] = c;
} else {
display_overflow_error = true;
}
@ -847,7 +849,8 @@ timeout_aborted:
reset_term();
}
boot(selected_menu_entry->body);
case 'e': {
case 'e':
case 'E': {
if (editor_enabled) {
if (selected_menu_entry->sub != NULL)
goto refresh;
@ -860,7 +863,8 @@ timeout_aborted:
}
break;
}
case 'c': {
case 'c':
case 'C': {
reset_term();
console();
goto refresh;