Fix: fixing push/pull for commit "Initital beggining of a CLI"

This commit is contained in:
AfonsoCMSousa
2026-08-03 14:58:20 +01:00
parent 403face1e6
commit 1dfe5d4fea
2 changed files with 129 additions and 20 deletions
+5 -8
View File
@@ -18,26 +18,23 @@ typedef struct {
} user; } user;
void kmain(void) { void kmain(void) {
user current_user = { user current_user = {.user_name = "admin", .user_hostname = "soraos", .user_id = 0};
.user_name = "admin",
.user_hostname = "soraos",
.user_id = 0
};
__clear_screen(); __clear_screen_colored(LIGHT_GREEN);
printf("SoraOS Kernel Initialized!\n"); printf("SoraOS Kernel Initialized!\n");
printf("\tWelcome to SoraOS!\n"); printf("\tWelcome to SoraOS!\n");
printf("\tKernel Version: %s\n", __KERNEL_VERSION); printf("\tKernel Version: %s\n", __KERNEL_VERSION);
printf("\tCompiled on: %s at %s\n\n", __DATE__, __TIME__); printf("\tCompiled on: %s at %s\n\n", __DATE__, __TIME__);
// TODO: CLI IDEA // TODO: CLI IDEA
int _count = printf("%s@%s:>", current_user.user_name, current_user.user_hostname); int _count = printf("%s@%s:>", current_user.user_name, current_user.user_hostname);
scursor(_count, text_pos.line); scursor(_count, text_pos.line);
// TODO: Enable user input handling // TODO: Enable user input handling
// char input_buffer[256];
// scanf("%s", input_buffer);
// printf("\nYou entered: %s\n", input_buffer);
// Infinite loop // Infinite loop
while (1) { while (1) {
+113 -1
View File
@@ -3,13 +3,23 @@
#include "types.h" #include "types.h"
#include <stdarg.h> #include <stdarg.h>
#include <strings.h> #include <stddef.h>
#define VGA_WIDTH 80 #define VGA_WIDTH 80
#define VGA_HEIGHT 25 #define VGA_HEIGHT 25
#define VGA_MEMORY_ADDRESS 0xB8000 #define VGA_MEMORY_ADDRESS 0xB8000
/*
* FOR INPUT
*/
#define KEYBOARD_BUFFER_SIZE 256
static char _keyboard_buffer[KEYBOARD_BUFFER_SIZE];
static uint16_t _kb_head = 0;
static uint16_t _kb_tail = 0;
/* IN VGA - Video Memory Arrya: /* IN VGA - Video Memory Arrya:
* short * short
* 1s byte (left most) -> TEXT COLOR * 1s byte (left most) -> TEXT COLOR
@@ -343,7 +353,109 @@ void scursor(unsigned int column, unsigned int line) {
__VGA_set_cursor_internal(column, line); __VGA_set_cursor_internal(column, line);
} }
static inline void __keyboard_buffer_push(char __c) {
_keyboard_buffer[_kb_head] = __c;
_kb_head = (_kb_head + 1) % KEYBOARD_BUFFER_SIZE;
}
static inline char __keyboard_buffer_pop() {
if (_kb_tail == _kb_head) {
return '\0';
}
char __c = _keyboard_buffer[_kb_tail];
_kb_tail = (_kb_tail + 1) % KEYBOARD_BUFFER_SIZE;
return __c;
}
static inline char __gets_internal(char *buffer, size_t max_length) {
size_t index = 0;
char __c;
while (index < max_length - 1) {
__c = __keyboard_buffer_pop();
if (__c == '\0') {
continue;
}
if (__c == '\n' || __c == '\r') {
buffer[index] = '\0';
break;
}
buffer[index++] = __c;
}
buffer[index] = '\0';
return index;
}
void gets(char *buffer, size_t max_length) {
__gets_internal(buffer, max_length);
}
static inline int __scanf_internal(const char *fmt, va_list args) {
char buffer[256];
__gets_internal(buffer, sizeof(buffer));
const char* p = fmt;
char* in = buffer;
int count = 0;
while (*p) {
if (*p == '%') {
p++;
if (*p == 'd') {
int* out = va_arg(args, int*);
int sign = 1;
int value = 0;
if (*in == '-') { sign = -1; in++; }
while (*in >= '0' && *in <= '9') {
value = value * 10 + (*in - '0');
in++;
}
*out = value * sign;
count++;
}
else if (*p == 's') {
char* out = va_arg(args, char*);
while (*in == ' ') in++; // skip spaces
while (*in && *in != ' ') {
*out++ = *in++;
}
*out = '\0';
count++;
}
else if (*p == 'c') {
char* out = va_arg(args, char*);
*out = *in++;
count++;
}
}
p++;
}
va_end(args);
return count;
}
int scanf(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
int result = __scanf_internal(fmt, args);
va_end(args);
return result;
}