core: split shell command into individual file and support command arg
This commit is contained in:
parent
b84d4dbcb8
commit
3a916908ef
12
headers/commands.h
Normal file
12
headers/commands.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void halt_cmd(char *arg);
|
||||||
|
void color_cmd(char *arg);
|
||||||
|
void date_cmd(char *arg);
|
||||||
|
void poweroff_cmd(char *arg);
|
||||||
|
void stack_cmd(char *arg);
|
||||||
|
void help_cmd(char *arg);
|
||||||
|
void reboot_cmd(char* arg);
|
||||||
|
void heap_cmd(char *arg);
|
||||||
|
void clear_cmd(char *arg);
|
||||||
|
void merdella_cmd(char *arg);
|
@ -1,51 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "debug.h"
|
|
||||||
#include "power.h"
|
|
||||||
|
|
||||||
#define PROMPT "> "
|
#define PROMPT "> "
|
||||||
|
|
||||||
[[__maybe_unused__]] static const char *POOP =
|
void shell_init();
|
||||||
" / ____/ / _ \\\n"
|
|
||||||
" _/ ___/_ / / \\___ \\_\n"
|
|
||||||
" / _/'-, `---._ / / \\_ \\\n"
|
|
||||||
" / ______/(0} `, , ` , ) / / \\_ \\\n"
|
|
||||||
" / V ; ` , ` ( / / ,'~~~~~~`, \\\n"
|
|
||||||
" | `.____,- ' (, ` , ) / / :`,-'\"\"`. \"; "
|
|
||||||
"|\n"
|
|
||||||
" | `-------._); , ` `, / / \\;: )``: |\n"
|
|
||||||
" / / ) ) ; ` ,, : / / `` : '; "
|
|
||||||
"\\\n"
|
|
||||||
"/ / ( (`;: ; ` ;:\\ / / ;;;, "
|
|
||||||
"\\\n"
|
|
||||||
"| / (: )``;:;;)`'`'`--./ / ____ _,-';;` "
|
|
||||||
"|\n"
|
|
||||||
"| | :` )`;)`)`' : / / ~~~~~ ~~~`--',.;;;| "
|
|
||||||
"|\n"
|
|
||||||
"| | `--;~~~~~ ` / /, \" \" \"` \",, \\ ;`` | "
|
|
||||||
" |\n"
|
|
||||||
"| | ( ; , / / ; `; ; | "
|
|
||||||
"|\n"
|
|
||||||
"| | (; ; ; ` / / ,` ` : | "
|
|
||||||
"><\n"
|
|
||||||
"| | (; / / / ` ; ; : |\n"
|
|
||||||
"| \\ ;(_; ; : / /` ; ; ,,,\"\"\";} `; / "
|
|
||||||
"><\n"
|
|
||||||
"\\ \\ : `; `; ` / /,;,'''' );;`); ; / >< "
|
|
||||||
" ><\n"
|
|
||||||
" \\ | ;' :; ;/ / (;` :( ; , ; | "
|
|
||||||
"><\n"
|
|
||||||
" | | |, `;; ,/ / `)`; `(; ` `; | "
|
|
||||||
"(`\\\n"
|
|
||||||
" | \\ ; ;; ``: / `).:` \\;, `. / _> "
|
|
||||||
")_\n"
|
|
||||||
" \\ \\_ ,-' ;`;;:;` / ;;'`;; `) )/ ,-' "
|
|
||||||
",-. `;\n"
|
|
||||||
" \\ \\_ ~~~,-`;`;,\" / ~~~~~ ,-' ; "
|
|
||||||
"`\"\"/ /\"\"\n"
|
|
||||||
" \\_ \\___\"\"\"/\"\" / `\"\"/\"\" "
|
|
||||||
"\n";
|
|
||||||
|
|
||||||
void shell_init(void);
|
|
||||||
void date(void);
|
|
||||||
void merdella(void);
|
|
7
src/shell/commands/clear_cmd.c
Normal file
7
src/shell/commands/clear_cmd.c
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "terminal.h"
|
||||||
|
|
||||||
|
void clear_cmd(char *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
terminal_clear();
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
#include "kprintf.h"
|
#include "kprintf.h"
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
|
|
||||||
void date(void)
|
void date_cmd(char *arg)
|
||||||
{
|
{
|
||||||
static const char *months[12] = {"January", "February", "March",
|
static const char *months[12] = {"January", "February", "March",
|
||||||
"April", "May", "June",
|
"April", "May", "June",
|
||||||
@ -10,6 +10,7 @@ void date(void)
|
|||||||
static const char *week_days[] = {"Sunday", "Monday", "Tuesday",
|
static const char *week_days[] = {"Sunday", "Monday", "Tuesday",
|
||||||
"Wednesday", "Thursday", "Friday",
|
"Wednesday", "Thursday", "Friday",
|
||||||
"Saturday"};
|
"Saturday"};
|
||||||
|
(void)arg;
|
||||||
struct rtc_date date = get_date();
|
struct rtc_date date = get_date();
|
||||||
|
|
||||||
kprintf(0, "%s. %d %s. %d %d:%d:%d\n", week_days[date.index_of_the_day],
|
kprintf(0, "%s. %d %s. %d %d:%d:%d\n", week_days[date.index_of_the_day],
|
7
src/shell/commands/halt_cmd.c
Normal file
7
src/shell/commands/halt_cmd.c
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "power.h"
|
||||||
|
|
||||||
|
void halt_cmd(char *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
halt();
|
||||||
|
}
|
7
src/shell/commands/heap_cmd.c
Normal file
7
src/shell/commands/heap_cmd.c
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "alloc.h"
|
||||||
|
|
||||||
|
void heap_cmd(char *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
show_alloc_mem();
|
||||||
|
}
|
49
src/shell/commands/merdella_cmd.c
Normal file
49
src/shell/commands/merdella_cmd.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "kprintf.h"
|
||||||
|
#include "shell.h"
|
||||||
|
|
||||||
|
[[__maybe_unused__]] static const char *POOP =
|
||||||
|
" / ____/ / _ \\\n"
|
||||||
|
" _/ ___/_ / / \\___ \\_\n"
|
||||||
|
" / _/'-, `---._ / / \\_ \\\n"
|
||||||
|
" / ______/(0} `, , ` , ) / / \\_ \\\n"
|
||||||
|
" / V ; ` , ` ( / / ,'~~~~~~`, \\\n"
|
||||||
|
" | `.____,- ' (, ` , ) / / :`,-'\"\"`. \"; "
|
||||||
|
"|\n"
|
||||||
|
" | `-------._); , ` `, / / \\;: )``: |\n"
|
||||||
|
" / / ) ) ; ` ,, : / / `` : '; "
|
||||||
|
"\\\n"
|
||||||
|
"/ / ( (`;: ; ` ;:\\ / / ;;;, "
|
||||||
|
"\\\n"
|
||||||
|
"| / (: )``;:;;)`'`'`--./ / ____ _,-';;` "
|
||||||
|
"|\n"
|
||||||
|
"| | :` )`;)`)`' : / / ~~~~~ ~~~`--',.;;;| "
|
||||||
|
"|\n"
|
||||||
|
"| | `--;~~~~~ ` / /, \" \" \"` \",, \\ ;`` | "
|
||||||
|
" |\n"
|
||||||
|
"| | ( ; , / / ; `; ; | "
|
||||||
|
"|\n"
|
||||||
|
"| | (; ; ; ` / / ,` ` : | "
|
||||||
|
"><\n"
|
||||||
|
"| | (; / / / ` ; ; : |\n"
|
||||||
|
"| \\ ;(_; ; : / /` ; ; ,,,\"\"\";} `; / "
|
||||||
|
"><\n"
|
||||||
|
"\\ \\ : `; `; ` / /,;,'''' );;`); ; / >< "
|
||||||
|
" ><\n"
|
||||||
|
" \\ | ;' :; ;/ / (;` :( ; , ; | "
|
||||||
|
"><\n"
|
||||||
|
" | | |, `;; ,/ / `)`; `(; ` `; | "
|
||||||
|
"(`\\\n"
|
||||||
|
" | \\ ; ;; ``: / `).:` \\;, `. / _> "
|
||||||
|
")_\n"
|
||||||
|
" \\ \\_ ,-' ;`;;:;` / ;;'`;; `) )/ ,-' "
|
||||||
|
",-. `;\n"
|
||||||
|
" \\ \\_ ~~~,-`;`;,\" / ~~~~~ ,-' ; "
|
||||||
|
"`\"\"/ /\"\"\n"
|
||||||
|
" \\_ \\___\"\"\"/\"\" / `\"\"/\"\" "
|
||||||
|
"\n";
|
||||||
|
|
||||||
|
void merdella_cmd(char *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
kprintf(POOP);
|
||||||
|
}
|
7
src/shell/commands/poweroff_cmd.c
Normal file
7
src/shell/commands/poweroff_cmd.c
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "power.h"
|
||||||
|
|
||||||
|
void poweroff_cmd(char *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
halt();
|
||||||
|
}
|
7
src/shell/commands/reboot.c
Normal file
7
src/shell/commands/reboot.c
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "power.h"
|
||||||
|
|
||||||
|
void reboot_cmd(char *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
reboot();
|
||||||
|
}
|
7
src/shell/commands/stack_cmd.c
Normal file
7
src/shell/commands/stack_cmd.c
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
void stack_cmd(char arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
print_stack();
|
||||||
|
}
|
@ -1,39 +1,41 @@
|
|||||||
#include "alloc.h"
|
#include "alloc.h"
|
||||||
|
#include "commands.h"
|
||||||
#include "kprintf.h"
|
#include "kprintf.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
|
|
||||||
#define NB_CMDS (sizeof(commands) / sizeof(commands[0]))
|
#define BORDER "==========================================================="
|
||||||
#define BORDER "==========================================================="
|
#define HEADER "Welcome to bozOShell - Available Commands"
|
||||||
#define HEADER "Welcome to bozOShell - Available Commands"
|
|
||||||
|
|
||||||
extern struct screen *screen;
|
|
||||||
|
|
||||||
struct shell_command {
|
struct shell_command {
|
||||||
char name[16];
|
char name[16];
|
||||||
char description[256];
|
char description[256];
|
||||||
void (*fn)(void);
|
void (*fn)(char *arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
static void help(void);
|
const struct shell_command commands[] = {
|
||||||
|
{"help", "Print this help menu", help_cmd},
|
||||||
static const struct shell_command commands[] = {
|
{"reboot", "Reboot the system", reboot_cmd},
|
||||||
{"help", "Print this help menu", help},
|
{"poweroff", "Shut down the system", poweroff_cmd},
|
||||||
{"reboot", "Reboot the system", reboot},
|
{"halt", "Stop all CPU functions", halt_cmd},
|
||||||
{"poweroff", "Shut down the system", halt},
|
{"stack", "Print the stack trace", stack_cmd},
|
||||||
{"halt", "Stop all CPU functions", halt},
|
{"heap", "Print the heaps", heap_cmd},
|
||||||
{"stack", "Print the stack trace", print_stack},
|
{"clear", "Clear the current terminal", clear_cmd},
|
||||||
{"heap", "Print the heaps", show_alloc_mem},
|
{"date", "Display the current time and date", date_cmd},
|
||||||
{"clear", "Clear the current terminal", terminal_clear},
|
{"merdella", "Surprise", merdella_cmd},
|
||||||
{"date", "Display the current time and date (UTC+0)", date},
|
// {"color", "Change the screen color", color},
|
||||||
{"merdella", "Surprise", merdella},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void help(void)
|
#define NB_CMDS (sizeof(commands) / sizeof(commands[0]))
|
||||||
|
|
||||||
|
extern struct screen *screen;
|
||||||
|
|
||||||
|
void help_cmd(char *arg)
|
||||||
{
|
{
|
||||||
const size_t padding = 15;
|
const size_t padding = 15;
|
||||||
|
|
||||||
|
(void)arg;
|
||||||
kprintf("%s\n", BORDER);
|
kprintf("%s\n", BORDER);
|
||||||
kprintf(" %s\n", HEADER);
|
kprintf(" %s\n", HEADER);
|
||||||
kprintf("%s\n", BORDER);
|
kprintf("%s\n", BORDER);
|
||||||
@ -103,7 +105,7 @@ static void read_line(void)
|
|||||||
screen->line[i] = '\0';
|
screen->line[i] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
void shell_init(void)
|
void shell_init()
|
||||||
{
|
{
|
||||||
while (1) {
|
while (1) {
|
||||||
kprintf(PROMPT);
|
kprintf(PROMPT);
|
||||||
@ -111,7 +113,8 @@ void shell_init(void)
|
|||||||
bool invalid = true;
|
bool invalid = true;
|
||||||
for (unsigned i = 0; i < NB_CMDS; i++) {
|
for (unsigned i = 0; i < NB_CMDS; i++) {
|
||||||
if (!strcmp(commands[i].name, screen->line)) {
|
if (!strcmp(commands[i].name, screen->line)) {
|
||||||
commands[i].fn();
|
commands[i].fn(screen->line +
|
||||||
|
strlen(commands[i].name) + 1);
|
||||||
invalid = false;
|
invalid = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
#include "kprintf.h"
|
|
||||||
#include "shell.h"
|
|
||||||
|
|
||||||
void merdella(void)
|
|
||||||
{
|
|
||||||
kprintf(POOP);
|
|
||||||
}
|
|
@ -33,8 +33,9 @@ void terminal_initialize(void)
|
|||||||
for (int i = 0; i < TERM_COUNT; i++) {
|
for (int i = 0; i < TERM_COUNT; i++) {
|
||||||
screens[i].row = 0;
|
screens[i].row = 0;
|
||||||
screens[i].column = 0;
|
screens[i].column = 0;
|
||||||
screens[i].color =
|
screens[i].default_color =
|
||||||
vga_entry_color(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
|
vga_entry_color(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
|
||||||
|
screens[i].color = screens[i].default_color;
|
||||||
memcpy(screens[i].buffer, TERM_BUF, sizeof(screen->buffer));
|
memcpy(screens[i].buffer, TERM_BUF, sizeof(screen->buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,6 +60,11 @@ void terminal_set_fg_color(uint8_t fg_color)
|
|||||||
screen->color = (screen->color & 0xF0) | fg_color;
|
screen->color = (screen->color & 0xF0) | fg_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void terminal_set_color(uint8_t color)
|
||||||
|
{
|
||||||
|
screen->color = color;
|
||||||
|
}
|
||||||
|
|
||||||
void terminal_putentryat(char c, uint8_t color, size_t x, size_t y)
|
void terminal_putentryat(char c, uint8_t color, size_t x, size_t y)
|
||||||
{
|
{
|
||||||
const size_t index = y * VGA_WIDTH + x;
|
const size_t index = y * VGA_WIDTH + x;
|
||||||
@ -172,5 +178,8 @@ void set_color_level(int level)
|
|||||||
VGA_COLOR_LIGHT_YELLOW, VGA_COLOR_LIGHT_YELLOW,
|
VGA_COLOR_LIGHT_YELLOW, VGA_COLOR_LIGHT_YELLOW,
|
||||||
VGA_COLOR_LIGHT_BLUE, VGA_COLOR_GREEN,
|
VGA_COLOR_LIGHT_BLUE, VGA_COLOR_GREEN,
|
||||||
VGA_COLOR_LIGHT_GREY};
|
VGA_COLOR_LIGHT_GREY};
|
||||||
|
|
||||||
|
if (level == 0)
|
||||||
|
terminal_set_color(screen->default_color);
|
||||||
terminal_set_fg_color(color_translation[level]);
|
terminal_set_fg_color(color_translation[level]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user