diff --git a/stage23/console.c b/stage23/console.c index 49a165b0..46fb14ad 100644 --- a/stage23/console.c +++ b/stage23/console.c @@ -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) { diff --git a/stage23/lib/libc.h b/stage23/lib/libc.h index 7f7d91bb..7e8add9d 100644 --- a/stage23/lib/libc.h +++ b/stage23/lib/libc.h @@ -2,6 +2,10 @@ #define __LIB__LIBC_H__ #include +#include + +bool isprint(int c); +bool isspace(int c); int toupper(int c); int tolower(int c); diff --git a/stage23/lib/libc.s2.c b/stage23/lib/libc.s2.c index 24af2bec..1b818135 100644 --- a/stage23/lib/libc.s2.c +++ b/stage23/lib/libc.s2.c @@ -4,6 +4,14 @@ #include #include +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; diff --git a/stage23/lib/readline.c b/stage23/lib/readline.c index c810dab8..f13347b7 100644 --- a/stage23/lib/readline.c +++ b/stage23/lib/readline.c @@ -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) diff --git a/stage23/menu.c b/stage23/menu.c index b0f6b60c..f4663340 100644 --- a/stage23/menu.c +++ b/stage23/menu.c @@ -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;