Skip to content

Commit

Permalink
feat(kernel): add a clear command
Browse files Browse the repository at this point in the history
  • Loading branch information
bemxio committed Jul 16, 2022
1 parent c7669de commit 07af204
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions kernel/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

void help(struct tokenized_string *tokens) {
kprintln("All of the commands:");

kprintln("`help` - shows this list");
kprintln("`echo` - prints the first argument that is provided");
kprintln("`clear` - clears the screen");
}

void echo(struct tokenized_string *tokens) {
kprintln(tokens->indices[1]);
}

void clear(struct tokenized_string *tokens) {
kclear();
}
1 change: 1 addition & 0 deletions kernel/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

void help(struct tokenized_string *tokens);
void echo(struct tokenized_string *tokens);
void clear(struct tokenized_string *tokens);

#endif
7 changes: 4 additions & 3 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include "commands.h"
#include "parser.h"

#define FUNC_AMOUNT 3
#define PROMPT "$ "

char **names[2] = {"help", "echo"};
int (*addresses[2])(struct tokenized_string *) = {&help, &echo};
char **names[FUNC_AMOUNT] = {"help", "echo", "clear"};
int (*addresses[FUNC_AMOUNT])(struct tokenized_string *) = {&help, &echo, &clear};

void command_error(char *exception) {
kprint("error: ");
Expand All @@ -21,7 +22,7 @@ void input_callback(char *buffer) {
struct tokenized_string *tokens = tokenize_string(buffer);
char *name = tokens->indices[0]; // the command name

int index = findsubstr(names, name, 2);
int index = findsubstr(names, name, FUNC_AMOUNT);

if (index == -1) { // command name not found
command_error("command not found");
Expand Down

0 comments on commit 07af204

Please sign in to comment.