limine/common/console.c

66 lines
2.0 KiB
C
Raw Normal View History

2021-10-09 14:32:57 +03:00
#include <stddef.h>
#include <stdint.h>
#include <config.h>
2021-10-09 14:32:57 +03:00
#include <console.h>
2021-12-12 00:22:48 +03:00
#include <menu.h>
2021-10-09 14:32:57 +03:00
#include <mm/pmm.h>
#include <lib/print.h>
#include <lib/readline.h>
#include <lib/libc.h>
2022-08-27 00:44:47 +03:00
#include <lib/misc.h>
2021-10-09 14:32:57 +03:00
#include <lib/term.h>
#include <lib/part.h>
#include <lib/config.h>
2021-10-09 14:32:57 +03:00
static void console_help(void) {
print(
"Available commands:\n"
2021-12-12 00:22:48 +03:00
"exit -- Exit Limine console.\n"
"clear -- Clear the console.\n"
"%s"
"lsvol -- List volumes.\n"
2021-10-09 14:32:57 +03:00
"version -- Print version.\n"
"copyright -- Print copyright.\n"
"help -- Print this help message.\n",
editor_enabled ? "editor -- Open an empty boot entry editor.\n" : ""
2021-10-09 14:32:57 +03:00
);
}
void console(void) {
print("Welcome to the Limine console.\nType 'help' for more information.\n\n");
char *prompt = ext_mem_alloc(256);
2021-10-09 14:32:57 +03:00
for (;;) {
print(">>> ");
readline("", prompt, 256);
if (strcmp(prompt, "help") == 0) {
console_help();
} else if (strcmp(prompt, "exit") == 0) {
break;
2022-01-29 01:56:10 +03:00
} else if (strcmp(prompt, "clear") == 0) {
print("\e[2J\e[H");
} else if (strcmp(prompt, "lsvol") == 0) {
list_volumes();
} else if (editor_enabled && strcmp(prompt, "editor") == 0) {
2021-12-12 00:22:48 +03:00
char *new_entry = config_entry_editor("New Entry", "");
if (new_entry != NULL) {
config_ready = true;
2021-12-12 00:22:48 +03:00
boot(new_entry);
}
2021-10-09 14:32:57 +03:00
} else if (strcmp(prompt, "version") == 0) {
print(LIMINE_VERSION "\n");
} else if (strcmp(prompt, "copyright") == 0) {
print(LIMINE_COPYRIGHT "\n");
print("Limine is distributed under the terms of the BSD-2-Clause license.\n");
2021-10-31 22:33:47 +03:00
print("There is ABSOLUTELY NO WARRANTY, to the extent permitted by law.\n");
2021-10-09 14:32:57 +03:00
} else if (*prompt != 0) {
print("Invalid command: `%s`.\n", prompt);
}
}
reset_term();
pmm_free(prompt, 256);
2021-10-09 14:32:57 +03:00
}