feature (shell): implemented basic interactions

This commit is contained in:
antifallobst 2023-05-02 21:21:07 +02:00
parent 0d36dac39b
commit c5cbf51e75
2 changed files with 25 additions and 1 deletions

View File

@ -1,4 +1,6 @@
#include "nox/stdio.h"
#include "nox/memory.h"
#include "nox/math.h"
#define COMMAND_BUFFER_SIZE 512
@ -26,14 +28,36 @@ int read_command(char* command_buffer) {
return pos;
}
bool handle_command(char* command_buffer) {
int command_length = strlen(command_buffer);
if (command_length < 2) return true;
if (memcmp(command_buffer, "help", min(4, command_length))) {
printf("Commands:\n");
printf(" help | shows this help message\n");
printf(" exit | exit noxsh\n");
} else if (memcmp(command_buffer, "exit", min(4, command_length))) {
printf("exiting noxsh\n");
return false;
} else {
printf("Unknown command: '");
printf(command_buffer);
printf("'\n");
}
return true;
}
void _start() {
printf("Welcome to the nox shell.\ntype 'help' for a list of commands\n");
bool running = true;
while(running) {
printf("\n>>> ");
printf("\n[/]=> ");
char command_buffer[COMMAND_BUFFER_SIZE];
read_command(command_buffer);
running = handle_command(command_buffer);
}
}

Binary file not shown.