39 lines
837 B
C
39 lines
837 B
C
|
#include "nox/stdio.h"
|
||
|
|
||
|
#define COMMAND_BUFFER_SIZE 512
|
||
|
|
||
|
int read_command(char* command_buffer) {
|
||
|
char chr = 0;
|
||
|
int pos = 0;
|
||
|
while (chr != '\n') {
|
||
|
chr = getc();
|
||
|
switch (chr) {
|
||
|
case '\b': {
|
||
|
if (pos > 0) pos--;
|
||
|
break;
|
||
|
}
|
||
|
default: {
|
||
|
if (pos < COMMAND_BUFFER_SIZE) {
|
||
|
command_buffer[pos] = chr;
|
||
|
pos++;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
command_buffer[pos] = '\0';
|
||
|
return pos;
|
||
|
}
|
||
|
|
||
|
void _start() {
|
||
|
printf("Welcome to the nox shell.\ntype 'help' for a list of commands\n");
|
||
|
|
||
|
bool running = true;
|
||
|
|
||
|
while(running) {
|
||
|
printf("\n>>> ");
|
||
|
char command_buffer[COMMAND_BUFFER_SIZE];
|
||
|
read_command(command_buffer);
|
||
|
}
|
||
|
}
|