mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2025-10-13 21:25:07 -07:00
addind more important kernel files and also fixing bugs
This commit is contained in:
60
kernel/shell.c
Normal file
60
kernel/shell.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "shell.h"
|
||||
#include "keyboard.h"
|
||||
#include "terminal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void execute(char *input) {
|
||||
if (strcmp(input, "help") == 0) {
|
||||
printf("Available commands: help, clear, exit\n");
|
||||
} else if (strcmp(input, "clear") == 0) {
|
||||
terminal_clear();
|
||||
} else {
|
||||
printf("Unknown command: %s\n", input);
|
||||
}
|
||||
}
|
||||
|
||||
void shell_loop()
|
||||
{
|
||||
char input[256];
|
||||
int index = 0;
|
||||
char c;
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("> ");
|
||||
index = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = keyboard_get_char(); // Waits for input
|
||||
|
||||
if (c == '\n' || c == '\r') // Enter key
|
||||
{
|
||||
input[index] = '\0';
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
else if (c == '\b' || c == 127) // Backspace
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
index--;
|
||||
printf("\b \b"); // Erase last char on screen
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index < sizeof(input) - 1) {
|
||||
input[index++] = c;
|
||||
putchar(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(input, "exit") == 0)
|
||||
break;
|
||||
|
||||
execute(input);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user