2021-10-09 14:32:57 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2022-02-21 01:05:53 +03:00
|
|
|
#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>
|
2022-07-01 18:30:53 +03:00
|
|
|
#include <lib/part.h>
|
2022-07-09 12:58:03 +03:00
|
|
|
#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"
|
2022-07-01 18:30:53 +03:00
|
|
|
"clear -- Clear the console.\n"
|
2022-03-02 15:31:09 +03:00
|
|
|
"%s"
|
2022-07-01 18:30:53 +03:00
|
|
|
"lsvol -- List volumes.\n"
|
2021-10-09 14:32:57 +03:00
|
|
|
"version -- Print version.\n"
|
|
|
|
"copyright -- Print copyright.\n"
|
2022-03-02 15:31:09 +03:00
|
|
|
"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");
|
|
|
|
|
2021-10-21 03:37:05 +03:00
|
|
|
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) {
|
2021-10-21 03:37:05 +03:00
|
|
|
break;
|
2022-01-29 01:56:10 +03:00
|
|
|
} else if (strcmp(prompt, "clear") == 0) {
|
2022-01-29 09:52:44 +03:00
|
|
|
print("\e[2J\e[H");
|
2022-07-01 18:30:53 +03:00
|
|
|
} else if (strcmp(prompt, "lsvol") == 0) {
|
|
|
|
list_volumes();
|
2022-03-02 15:31:09 +03:00
|
|
|
} 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) {
|
2022-07-09 12:58:03 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2021-10-21 03:37:05 +03:00
|
|
|
|
|
|
|
reset_term();
|
|
|
|
pmm_free(prompt, 256);
|
2021-10-09 14:32:57 +03:00
|
|
|
}
|