From 19141e688364c6c579c77c3e8aec4d0c91fe17ee Mon Sep 17 00:00:00 2001 From: 0x35c Date: Wed, 11 Sep 2024 15:51:40 +0200 Subject: [PATCH] fix: screen switch now works well with the shell and its "history" --- libbozo/headers/string.h | 3 ++- libbozo/src/string/memset.c | 11 +++++++++++ src/shell/exec.c | 10 +++++++--- src/terminal/put.c | 3 +++ 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 libbozo/src/string/memset.c diff --git a/libbozo/headers/string.h b/libbozo/headers/string.h index 0c7686a..3584da7 100644 --- a/libbozo/headers/string.h +++ b/libbozo/headers/string.h @@ -8,4 +8,5 @@ int strncmp(const char *s1, const char *s2, size_t n); size_t strlen(const char *str); char *strstr(const char *haystack, const char *needle); void *memcpy(void *dest, const void *src, size_t n); -int memcmp(const void *s1, const void *s2, size_t n); \ No newline at end of file +int memcmp(const void *s1, const void *s2, size_t n); +void *memset(void *str, int c, size_t n); diff --git a/libbozo/src/string/memset.c b/libbozo/src/string/memset.c new file mode 100644 index 0000000..0b37c5b --- /dev/null +++ b/libbozo/src/string/memset.c @@ -0,0 +1,11 @@ +#include +#include + +void *memset(void *str, int c, size_t n) +{ + uint8_t *c1 = (uint8_t *)str; + + for (size_t i = 0; i < n; i++) + c1[i] = c; + return c1; +} diff --git a/src/shell/exec.c b/src/shell/exec.c index e67c8d5..b46ffd8 100644 --- a/src/shell/exec.c +++ b/src/shell/exec.c @@ -40,7 +40,7 @@ static CMD_TOK find_command(char *line) return command; } -static void read_line(char *buf, size_t size) +static void read_line(void) { size_t i = 0; struct key_event ev; @@ -50,6 +50,9 @@ static void read_line(char *buf, size_t size) ev = terminal_getkey(); if (ev.c == '\n') break; + char *buf = screen->line; + i = strlen(screen->line); + const size_t size = sizeof(screen->line); if (prev_scan_code != ev.scan_code && ev.scan_code) { if (ev.scan_code == KEY_BACKSPACE && i) { buf[--i] = '\0'; @@ -67,14 +70,14 @@ static void read_line(char *buf, size_t size) prev_scan_code = ev.scan_code; } kprintf(0, "\n"); - buf[i] = '\0'; + screen->line[i] = '\0'; } void shell_init(void) { while (1) { kprintf(0, PROMPT); - read_line(screen->line, sizeof(screen->line)); + read_line(); switch (find_command(screen->line)) { case HELP: kprintf(0, "Welcome to bozOShell, the shell of " @@ -107,5 +110,6 @@ void shell_init(void) default: break; } + memset(screen->line, '\0', sizeof(screen->line)); } } diff --git a/src/terminal/put.c b/src/terminal/put.c index c9aa3a3..877009d 100644 --- a/src/terminal/put.c +++ b/src/terminal/put.c @@ -1,5 +1,6 @@ #include "ctype.h" #include "kprintf.h" +#include "shell.h" #include "string.h" #include "sys/io.h" #include "terminal.h" @@ -44,6 +45,8 @@ void terminal_set_screen(int pos) screen = &screens[pos]; memcpy(TERM_BUF, screen->buffer, sizeof(screen->buffer)); update_cursor(); + if (TERM_BUF[0] == vga_entry(' ', VGA_COLOR_WHITE)) + kprintf(0, PROMPT); } void terminal_setcolor(uint8_t color)