From 4a99b82e153e356cffc3957d8c7dbc8719be931a Mon Sep 17 00:00:00 2001 From: Starnakin Date: Wed, 18 Dec 2024 23:56:17 +0100 Subject: [PATCH] add: backspace work with vbe --- headers/shell.h | 3 +-- headers/terminal.h | 5 +++++ src/shell/exec.c | 37 +++++++++++++++++-------------------- src/terminal/put.c | 34 ++++++++++++++++++++++++++++++---- 4 files changed, 53 insertions(+), 26 deletions(-) diff --git a/headers/shell.h b/headers/shell.h index 462878c..c5a2fec 100644 --- a/headers/shell.h +++ b/headers/shell.h @@ -2,5 +2,4 @@ #define PROMPT "> " -void shell_init(void); -void auto_complete(void); +void shell_init(void); \ No newline at end of file diff --git a/headers/terminal.h b/headers/terminal.h index 21201c9..ee47770 100644 --- a/headers/terminal.h +++ b/headers/terminal.h @@ -1,5 +1,7 @@ #pragma once +#include "font.h" +#include "icon.h" #include "keyboard.h" #include #include @@ -19,6 +21,8 @@ struct screen { uint32_t bg_color; uint16_t buffer[VGA_WIDTH * VGA_HEIGHT]; uint32_t default_color; + struct icon *backgound; + struct font *font; char line[256]; }; @@ -62,3 +66,4 @@ void terminal_set_default_bg_color(uint32_t fg_color); void terminal_change_default_fg_color(uint32_t color); uint32_t terminal_get_default_color(void); uint8_t terminal_get_char(int column, int row); +void terminal_remove_last_char(void); \ No newline at end of file diff --git a/src/shell/exec.c b/src/shell/exec.c index ccc47cc..2d973d9 100644 --- a/src/shell/exec.c +++ b/src/shell/exec.c @@ -2,7 +2,6 @@ #include "alloc.h" #include "commands.h" -#include "ctype.h" #include "font.h" #include "kprintf.h" #include "shell.h" @@ -58,7 +57,7 @@ void help_cmd(char *arg) kprintf("%s\n", BORDER); } -void auto_complete(void) +static void auto_complete(void) { const size_t len = strlen(screen->line); int nb_matches = 0; @@ -85,38 +84,36 @@ static char *get_line(void) { size_t i = 0; struct key_event ev; + const size_t size = sizeof(screen->line); while (1) { ev = get_key(); + if (!ev.scan_code) + continue; if (ev.c == '\n') break; char *buf = screen->line; i = strlen(screen->line); - const size_t size = sizeof(screen->line); - if (ev.scan_code) { - if (ev.scan_code == KEY_BACKSPACE) { - if (!i) - continue; - buf[--i] = '\0'; - move_cursor(LEFT); - /* terminal_refresh(); */ - move_cursor(LEFT); - } else if (ev.scan_code == KEY_TAB && i) { - auto_complete(); - } else if (ev.c && i < size - 1) { - kprintf("%c", ev.c); - buf[i++] = ev.c; - } - if (i >= size) - break; + if (ev.scan_code == KEY_BACKSPACE) { + if (!i) + continue; + terminal_remove_last_char(); + buf[--i] = '\0'; + } else if (ev.scan_code == KEY_TAB && i) { + auto_complete(); + } else if (ev.c && i < size - 1) { + kprintf("%c", ev.c); + buf[i++] = ev.c; } + if (i >= size) + break; } kprintf("\n"); screen->line[i] = '\0'; return screen->line; } -void shell_init() +void shell_init(void) { while (1) { kprintf(PROMPT); diff --git a/src/terminal/put.c b/src/terminal/put.c index 24d4124..ed268ed 100644 --- a/src/terminal/put.c +++ b/src/terminal/put.c @@ -2,7 +2,6 @@ #include "debug.h" #include "font.h" #include "fonts/eating_pasta_regular_13.h" -#include "fonts/minecraft_medium_13.h" #include "icons/image.h" #include "kprintf.h" #include "shell.h" @@ -17,8 +16,6 @@ static struct screen screens[TERM_COUNT]; struct screen *screen = &screens[0]; -struct font *current_font = eating_pasta_regular_13_font; -struct icon *terminal_bg = &image_icon; static struct font get_font_node(int c); static void terminal_scroll(void); @@ -31,6 +28,35 @@ void terminal_initialize(void) screens[i].column = 0; screens[i].default_color = 0xffffff; screens[i].fg_color = screens[i].default_color; + screens[i].backgound = &image_icon; + screens[i].font = eating_pasta_regular_13_font; + } + // draw_icon(0, 0, screen->backgound); +} + +void terminal_remove_last_char(void) +{ + if (screen->column) + screen->column--; + else if (screen->row) { + screen->column = VGA_WIDTH - 1; + screen->row--; + } + uint32_t pos_x = (screen->column) * FONT_SIZE; + uint32_t pos_y = screen->row * FONT_SIZE; + + struct font node = get_font_node( + screen->buffer[screen->row * VGA_WIDTH + screen->column]); + screen->buffer[screen->row * VGA_WIDTH + screen->column] = '\0'; + for (uint32_t y = 0; y < node.height; y++) { + for (uint32_t x = 0; x < node.width; x++) { + struct icon *bg = screen->backgound; + uint32_t pixel = 0; + if (bg->width > pos_x + x && bg->height > pos_y + y) + pixel = bg->pixels[(pos_y + y) * bg->width + + (pos_x + x)]; + put_pixel(pixel, pos_x + x, pos_y + y); + } } } @@ -90,7 +116,7 @@ void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color, static struct font get_font_node(int c) { - return current_font[c]; + return screen->font[c]; } /* void terminal_refresh(void) */