fix: screen switch now works well with the shell and its "history"

This commit is contained in:
0x35c 2024-09-11 15:51:40 +02:00
parent bc99b99c82
commit 19141e6883
4 changed files with 23 additions and 4 deletions

View File

@ -8,4 +8,5 @@ int strncmp(const char *s1, const char *s2, size_t n);
size_t strlen(const char *str); size_t strlen(const char *str);
char *strstr(const char *haystack, const char *needle); char *strstr(const char *haystack, const char *needle);
void *memcpy(void *dest, const void *src, size_t n); void *memcpy(void *dest, const void *src, size_t n);
int memcmp(const void *s1, const void *s2, size_t n); int memcmp(const void *s1, const void *s2, size_t n);
void *memset(void *str, int c, size_t n);

View File

@ -0,0 +1,11 @@
#include <stddef.h>
#include <stdint.h>
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;
}

View File

@ -40,7 +40,7 @@ static CMD_TOK find_command(char *line)
return command; return command;
} }
static void read_line(char *buf, size_t size) static void read_line(void)
{ {
size_t i = 0; size_t i = 0;
struct key_event ev; struct key_event ev;
@ -50,6 +50,9 @@ static void read_line(char *buf, size_t size)
ev = terminal_getkey(); ev = terminal_getkey();
if (ev.c == '\n') if (ev.c == '\n')
break; 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 (prev_scan_code != ev.scan_code && ev.scan_code) {
if (ev.scan_code == KEY_BACKSPACE && i) { if (ev.scan_code == KEY_BACKSPACE && i) {
buf[--i] = '\0'; buf[--i] = '\0';
@ -67,14 +70,14 @@ static void read_line(char *buf, size_t size)
prev_scan_code = ev.scan_code; prev_scan_code = ev.scan_code;
} }
kprintf(0, "\n"); kprintf(0, "\n");
buf[i] = '\0'; screen->line[i] = '\0';
} }
void shell_init(void) void shell_init(void)
{ {
while (1) { while (1) {
kprintf(0, PROMPT); kprintf(0, PROMPT);
read_line(screen->line, sizeof(screen->line)); read_line();
switch (find_command(screen->line)) { switch (find_command(screen->line)) {
case HELP: case HELP:
kprintf(0, "Welcome to bozOShell, the shell of " kprintf(0, "Welcome to bozOShell, the shell of "
@ -107,5 +110,6 @@ void shell_init(void)
default: default:
break; break;
} }
memset(screen->line, '\0', sizeof(screen->line));
} }
} }

View File

@ -1,5 +1,6 @@
#include "ctype.h" #include "ctype.h"
#include "kprintf.h" #include "kprintf.h"
#include "shell.h"
#include "string.h" #include "string.h"
#include "sys/io.h" #include "sys/io.h"
#include "terminal.h" #include "terminal.h"
@ -44,6 +45,8 @@ void terminal_set_screen(int pos)
screen = &screens[pos]; screen = &screens[pos];
memcpy(TERM_BUF, screen->buffer, sizeof(screen->buffer)); memcpy(TERM_BUF, screen->buffer, sizeof(screen->buffer));
update_cursor(); update_cursor();
if (TERM_BUF[0] == vga_entry(' ', VGA_COLOR_WHITE))
kprintf(0, PROMPT);
} }
void terminal_setcolor(uint8_t color) void terminal_setcolor(uint8_t color)