input: Implement console input handling and add shell for real this time

Self explanatory, we finally have a working ish shell

Now we need to do some more stuff or something, probably work on a fork or something

Signed-off-by: kaguya <vpshinomiya@protonmail.com>

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
kaguya
2026-04-28 01:31:21 -04:00
parent 7d99745ff9
commit 2fa39ad85a
8 changed files with 135 additions and 3 deletions
+84 -1
View File
@@ -1,6 +1,7 @@
#include "../include/syscalls.h"
#define STDOUT 1
#define STDIN 0
#define STDOUT 1
unsigned strlen(const char* str)
{
@@ -13,6 +14,64 @@ unsigned strlen(const char* str)
return len;
}
static int strcmp(const char* a, const char* b)
{
while (*a && (*a == *b)) {
a++;
b++;
}
return *(unsigned char*)a - *(unsigned char*)b;
}
static void print(const char* s)
{
syscall(SYS_WRITE, STDOUT, (unsigned long)s, strlen(s), 0, 0, 0);
}
static void readline(char* buf, unsigned long max)
{
unsigned long i = 0;
while (i < max - 1)
{
char c;
long n = syscall(SYS_READ, STDIN, (unsigned long)&c, 1, 0, 0, 0);
if (n <= 0)
continue;
if (c == '\n')
break;
if (c == '\b') {
if (i > 0) i--;
continue;
}
buf[i++] = c;
}
buf[i] = '\0';
}
static void cat(const char* path)
{
unsigned char buf[256];
long fd = syscall(SYS_OPEN, (unsigned long)path, 0, 0, 0, 0, 0);
if (fd < 0) {
print("cat: cannot open file\n");
return;
}
long n = syscall(SYS_READ, fd, (unsigned long)buf, sizeof(buf), 0, 0, 0);
syscall(SYS_CLOSE, fd, 0, 0, 0, 0, 0);
if (n > 0)
syscall(SYS_WRITE, STDOUT, (unsigned long)buf, n, 0, 0, 0);
}
void main()
{
const unsigned char* path = "/qwerty.txt";
@@ -41,6 +100,30 @@ void main()
// ── print buffer to stdout ───────────────
syscall(SYS_WRITE, STDOUT, (unsigned long)buf, n, 0, 0, 0);
char line[128];
while (1)
{
print("> ");
readline(line, sizeof(line));
if (strcmp(line, "exit") == 0)
break;
// simple "cat <path>"
if (line[0] == 'c' && line[1] == 'a' && line[2] == 't' && line[3] == ' ')
{
cat(&line[4]);
continue;
}
if (line[0] != '\0')
print("Unknown command\n");
}
while (1);
// ── done ────────────────────────────────
while (1);
}