From 61debdcb85792eddee22543269ec1ad34714ee0b Mon Sep 17 00:00:00 2001 From: 0x35c Date: Thu, 19 Dec 2024 11:03:09 +0100 Subject: [PATCH] fix: autocomplete working again (ratio starnakin) and clean some stuff --- headers/fonts/consolas_regular_13.h | 648 ++++++++++++++++++++++++++++ headers/terminal.h | 4 +- src/shell/exec.c | 35 +- src/terminal/put.c | 46 +- 4 files changed, 682 insertions(+), 51 deletions(-) create mode 100644 headers/fonts/consolas_regular_13.h diff --git a/headers/fonts/consolas_regular_13.h b/headers/fonts/consolas_regular_13.h new file mode 100644 index 0000000..7ec359b --- /dev/null +++ b/headers/fonts/consolas_regular_13.h @@ -0,0 +1,648 @@ +#pragma once + +#include + +#include "font.h" + +struct font consolas_regular_13_font[] = {\ + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, + { + .width = 1, + .height = 1, + .bitmap = " ", + }, + { + .width = 3, + .height = 13, + .bitmap = "## ## ## ## ## ## ## ## ## ## #########", + }, + { + .width = 6, + .height = 5, + .bitmap = "##############################", + }, + { + .width = 10, + .height = 12, + .bitmap = " ## ## ## ## ## ## #################### ## ## ## ## #################### ## ## ## ## ## ## ", + }, + { + .width = 8, + .height = 15, + .bitmap = " ### ## ##### ###### ## ## ## ## ##### ###### ##### ### ## ### ######### ###### ## ## ", + }, + { + .width = 11, + .height = 13, + .bitmap = " ### ## ##### ### ## ## ## ## ## ## ######## ### ## ## ###### ####### ## ## ## ### ## ## ## ##### ## ### ", + }, + { + .width = 11, + .height = 13, + .bitmap = " #### ###### ## ## ## ## ###### #### #### ## ###### ## ## ##### ## #### ## #### ######## #### ### ", + }, + { + .width = 3, + .height = 5, + .bitmap = "###############", + }, + { + .width = 5, + .height = 16, + .bitmap = " # ### ## ## ## ## ## ## ## ## ## ## ## ## ### # ", + }, + { + .width = 5, + .height = 16, + .bitmap = " # ### ## ## ## ## ## ## ## ## ## ## ## ## ### # ", + }, + { + .width = 8, + .height = 8, + .bitmap = " ## # ## # ######## ###### ###### ######## # ## # ## ", + }, + { + .width = 8, + .height = 8, + .bitmap = " ## ## ## ################ ## ## ## ", + }, + { + .width = 5, + .height = 6, + .bitmap = " ### #### ### ####### ### ", + }, + { + .width = 6, + .height = 2, + .bitmap = "############", + }, + { + .width = 4, + .height = 3, + .bitmap = " ## ########", + }, + { + .width = 9, + .height = 15, + .bitmap = " ## ## ### ## ### ## ### ## ## ### ## ### ## ### ## ", + }, + { + .width = 8, + .height = 12, + .bitmap = " #### ###### ## ## ## ##### ###### ########## ###### ##### ## ## ## ###### #### ", + }, + { + .width = 8, + .height = 12, + .bitmap = " ## #### ##### ## ## ## ## ## ## ## ## ################", + }, + { + .width = 8, + .height = 12, + .bitmap = " #### ###### # ## ## ## ### ## ### ### ### ################", + }, + { + .width = 7, + .height = 12, + .bitmap = "##### ####### ## ## ## ##### ##### ## ## ######## ##### ", + }, + { + .width = 10, + .height = 12, + .bitmap = " ### ### #### ##### ## ## ### ## ### ## ## ## #################### ## ## ", + }, + { + .width = 7, + .height = 12, + .bitmap = "###### ###### ## ## ##### ###### ## ## ## ######### ##### ", + }, + { + .width = 8, + .height = 12, + .bitmap = " #### ##### ## ## ###### ####### ## #### #### ##### ### ###### #### ", + }, + { + .width = 8, + .height = 12, + .bitmap = "################ ### ## ### ## ### ## ### ### ### ### ", + }, + { + .width = 8, + .height = 12, + .bitmap = " #### ######### #### ##### ### ###### ###### ### ##### #### ######### #### ", + }, + { + .width = 8, + .height = 12, + .bitmap = " #### ###### ### ##### #### #### ## ####### ###### ## ## ##### #### ", + }, + { + .width = 3, + .height = 9, + .bitmap = "######### #########", + }, + { + .width = 5, + .height = 12, + .bitmap = " ### ### ### ### #### ### ####### ### ", + }, + { + .width = 7, + .height = 10, + .bitmap = " # ### ### #### #### #### #### ### ### # ", + }, + { + .width = 8, + .height = 5, + .bitmap = "################ ################", + }, + { + .width = 7, + .height = 10, + .bitmap = " # ### ### #### #### #### #### ### ### # ", + }, + { + .width = 6, + .height = 13, + .bitmap = "### ##### ### ## ## ##### #### ## ## ## ### ### ### ", + }, + { + .width = 10, + .height = 16, + .bitmap = " #### ####### ## ## ## ## ## ##################### ######## ######## ######## ############## ## ###### ## ## ## ####### ##### ", + }, + { + .width = 12, + .height = 12, + .bitmap = " ### #### #### ###### ## ## ## ## ### ### ######## ######## ### ### ## ## ### ###", + }, + { + .width = 8, + .height = 12, + .bitmap = "###### ########## #### #### ########## ####### ## #### #### ######### ###### ", + }, + { + .width = 8, + .height = 12, + .bitmap = " #### ###### ## ### ## ## ## ## ## ## # ####### #### ", + }, + { + .width = 8, + .height = 12, + .bitmap = "##### ####### ## ## ## #### #### #### #### #### ##### ## ####### ##### ", + }, + { + .width = 7, + .height = 12, + .bitmap = "################ ## ## ################ ## ## ##############", + }, + { + .width = 7, + .height = 12, + .bitmap = "################ ## ## ################ ## ## ## ## ", + }, + { + .width = 8, + .height = 12, + .bitmap = " #### ###### ## #### ## ## ###### ###### #### ## ## ## ####### #### ", + }, + { + .width = 8, + .height = 12, + .bitmap = "## #### #### #### #### #################### #### #### #### #### ##", + }, + { + .width = 8, + .height = 12, + .bitmap = "################ ## ## ## ## ## ## ## ## ################", + }, + { + .width = 6, + .height = 12, + .bitmap = "############ ## ## ## ## ## ## ### ####### ### ", + }, + { + .width = 10, + .height = 12, + .bitmap = "## ### ## ### ## ### ## ### ##### #### #### ##### ## ### ## ### ## ### ## ### ", + }, + { + .width = 7, + .height = 12, + .bitmap = "## ## ## ## ## ## ## ## ## ## ##############", + }, + { + .width = 10, + .height = 12, + .bitmap = "### ####### ######## ######## ############################## ###### ## ###### ###### ###### ###### ###", + }, + { + .width = 8, + .height = 12, + .bitmap = "### ##### ###### ###### ###### #### ## #### ## #### ###### ###### ###### ##### ###", + }, + { + .width = 10, + .height = 12, + .bitmap = " #### ######## ## ## ### #### #### #### #### #### ### ## ## ######## #### ", + }, + { + .width = 8, + .height = 12, + .bitmap = "###### ####### ## ##### #### #### ########## ###### ## ## ## ## ", + }, + { + .width = 9, + .height = 15, + .bitmap = " #### ####### ## ## ## #### #### #### #### #### ## ## ## ####### ##### ## # ##### ### ", + }, + { + .width = 8, + .height = 12, + .bitmap = "##### ####### ## ## ## ## ## ## ###### ##### ## ### ## ### ## ### ## ##### ###", + }, + { + .width = 8, + .height = 12, + .bitmap = " #### ###### ## # ## ### ##### ##### ### #### ######### ##### ", + }, + { + .width = 8, + .height = 12, + .bitmap = "################ ## ## ## ## ## ## ## ## ## ## ", + }, + { + .width = 8, + .height = 12, + .bitmap = "## #### #### #### #### #### #### #### #### #### ### ###### #### ", + }, + { + .width = 12, + .height = 12, + .bitmap = "### ### ### ## ### ### ## ## ### ### ### ### ## ## ###### ###### #### #### ### ", + }, + { + .width = 10, + .height = 12, + .bitmap = " ## # ## ## ## ## ## ## ## ## ## ## ## ## ######## ######## ######## ######## ### ### ### ### ", + }, + { + .width = 10, + .height = 12, + .bitmap = "### ### ## ## ### ### ###### #### #### #### #### ###### ### ### ### ### ### ###", + }, + { + .width = 10, + .height = 12, + .bitmap = "## ##### ### ## ## ## ## ###### #### #### ## ## ## ## ## ", + }, + { + .width = 8, + .height = 12, + .bitmap = "################ ## ### ## ### ### ### ### ## ################", + }, + { + .width = 5, + .height = 16, + .bitmap = "############ ## ## ## ## ## ## ## ## ## ## ## ##########", + }, + { + .width = 9, + .height = 15, + .bitmap = "## ### ## ### ## ### ## ## ### ## ### ## ### ## ## ", + }, + { + .width = 5, + .height = 16, + .bitmap = "########## ## ## ## ## ## ## ## ## ## ## ## ############", + }, + { + .width = 10, + .height = 6, + .bitmap = " ## #### ###### ## ## ## ## ### ###", + }, + { + .width = 10, + .height = 2, + .bitmap = "####################", + }, + { + .width = 7, + .height = 5, + .bitmap = " ### ### ## ", + }, + { + .width = 7, + .height = 9, + .bitmap = " #### ###### # ## ############## #### ########## ######", + }, + { + .width = 8, + .height = 13, + .bitmap = "## ## ## ## ###### ####### ### #### #### #### #### ########## ##### ", + }, + { + .width = 7, + .height = 9, + .bitmap = " #### ######### ### ## ## ### # ###### #### ", + }, + { + .width = 8, + .height = 13, + .bitmap = " ## ## ## ## ###### ########## #### #### #### #### ### ####### ### ##", + }, + { + .width = 8, + .height = 9, + .bitmap = " #### ###### ### #################### ### ####### ######", + }, + { + .width = 9, + .height = 13, + .bitmap = " #### ##### ## ## ## ####### ####### ## ## ## ## ## ## ", + }, + { + .width = 8, + .height = 12, + .bitmap = " ################ ## ## ## ####### ###### ## ####### ########## ########## ##### ", + }, + { + .width = 7, + .height = 13, + .bitmap = "## ## ## ## ###### ########## #### #### #### #### #### #### ##", + }, + { + .width = 8, + .height = 13, + .bitmap = " ### ### ### ##### ##### ## ## ## ## ## ################", + }, + { + .width = 7, + .height = 16, + .bitmap = " ### ### ### ############## ## ## ## ## ## ## ### ######## #### ", + }, + { + .width = 9, + .height = 13, + .bitmap = "## ## ## ## ## ### ## ### ##### #### #### ##### ## ### ## ### ## ### ", + }, + { + .width = 8, + .height = 13, + .bitmap = "##### ##### ## ## ## ## ## ## ## ## ## ################", + }, + { + .width = 8, + .height = 9, + .bitmap = "#### ## ################## ## #### ## #### ## #### ## #### ## #### ## ##", + }, + { + .width = 7, + .height = 9, + .bitmap = "###### ########## #### #### #### #### #### #### ##", + }, + { + .width = 8, + .height = 9, + .bitmap = " #### ###### ### ##### #### #### ##### ### ###### #### ", + }, + { + .width = 8, + .height = 12, + .bitmap = "###### ####### ### #### #### #### #### ########## ###### ## ## ## ", + }, + { + .width = 8, + .height = 12, + .bitmap = " ###### ########## #### #### #### #### ### ####### ###### ## ## ##", + }, + { + .width = 7, + .height = 9, + .bitmap = "###### ########## #### #### ## ## ## ## ", + }, + { + .width = 7, + .height = 9, + .bitmap = " ##### ###### ## #### ##### #### ############### ", + }, + { + .width = 9, + .height = 12, + .bitmap = " # ## ## ################## ## ## ## ## ## ###### #####", + }, + { + .width = 7, + .height = 9, + .bitmap = "## #### #### #### #### #### #### ########## ######", + }, + { + .width = 10, + .height = 9, + .bitmap = "### ### ## ## ### ### ## ## ## ## ###### #### #### ## ", + }, + { + .width = 10, + .height = 9, + .bitmap = "### ### ## ## ## ## ## ## ## ## ######## ######## ######## ### #### ### ### ", + }, + { + .width = 11, + .height = 9, + .bitmap = " ### ### ### ### ### ### ##### #### #### ###### ###### ### ### ", + }, + { + .width = 10, + .height = 12, + .bitmap = "### ### ### ## ### ### ## ## ###### ##### #### ### ## ### ##### #### ", + }, + { + .width = 7, + .height = 9, + .bitmap = "############## ## ## ### ## ### ##############", + }, + { + .width = 7, + .height = 16, + .bitmap = " ### #### ## ## ## ## ## ### #### ## ## ## ## ## ##### ####", + }, + { + .width = 2, + .height = 18, + .bitmap = "####################################", + }, + { + .width = 7, + .height = 16, + .bitmap = "### #### ## ## ## ## ## ### #### ## ## ## ## ## ##### #### ", + }, + { + .width = 9, + .height = 4, + .bitmap = " ### ######## #### ######## #### ", + }, + { + .width = 0, + .height = 0, + .bitmap = NULL, + }, +}; \ No newline at end of file diff --git a/headers/terminal.h b/headers/terminal.h index ee47770..d637330 100644 --- a/headers/terminal.h +++ b/headers/terminal.h @@ -21,7 +21,7 @@ struct screen { uint32_t bg_color; uint16_t buffer[VGA_WIDTH * VGA_HEIGHT]; uint32_t default_color; - struct icon *backgound; + struct icon *background; struct font *font; char line[256]; }; @@ -66,4 +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 +void terminal_remove_last_char(void); diff --git a/src/shell/exec.c b/src/shell/exec.c index ce7459f..5ba9e74 100644 --- a/src/shell/exec.c +++ b/src/shell/exec.c @@ -76,36 +76,35 @@ static void auto_complete(void) kprintf("%c", screen->line[i]); } } -void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color, - size_t x, size_t y); -struct font get_font_node(int c); static char *get_line(void) { size_t i = 0; struct key_event ev; - const size_t size = sizeof(screen->line); - do { + while (1) { ev = get_key(); - if (!ev.scan_code) - continue; if (ev.c == '\n') break; char *buf = screen->line; i = strlen(screen->line); - 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; + const size_t size = sizeof(screen->line); + if (ev.scan_code) { + if (ev.scan_code == KEY_BACKSPACE) { + if (!i) + continue; + buf[--i] = '\0'; + terminal_remove_last_char(); + } 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; } - } while (i < size); + } kprintf("\n"); screen->line[i] = '\0'; return screen->line; diff --git a/src/terminal/put.c b/src/terminal/put.c index 39d6c61..661ba7d 100644 --- a/src/terminal/put.c +++ b/src/terminal/put.c @@ -1,8 +1,8 @@ #include "ctype.h" #include "debug.h" #include "font.h" -#include "fonts/eating_pasta_regular_13.h" -#include "icons/image.h" +#include "fonts/consolas_regular_13.h" +/* #include "icons/image.h" */ #include "kprintf.h" #include "shell.h" #include "string.h" @@ -28,11 +28,10 @@ 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; + /* screens[i].background = &image_icon; */ + screens[i].font = consolas_regular_13_font; memset(screens[i].line, 0, sizeof(screen->line)); } - // draw_icon(0, 0, screen->backgound); } void terminal_remove_last_char(void) @@ -51,12 +50,15 @@ void terminal_remove_last_char(void) 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); + // Current bg is taking too much memory + // so we do a black bg for now + /* struct icon *bg = screen->background; */ + /* 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(0, pos_x + x, pos_y + y); } } } @@ -120,18 +122,6 @@ static struct font get_font_node(int c) return screen->font[c]; } -/* void terminal_refresh(void) */ -/* { */ -/* memset(display.buff, 0, display.height * display.pitch); */ -/* for (size_t i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) { */ -/* const uint32_t x = (i % VGA_WIDTH) * FONT_SIZE; */ -/* const uint32_t y = (i / VGA_WIDTH) * FONT_SIZE; */ -/* terminal_putentryat(get_font_node(screen->buffer[i]), */ -/* screen->fg_color, screen->bg_color, x, y); - */ -/* } */ -/* } */ - static void terminal_scroll(void) { screen->row--; @@ -211,19 +201,12 @@ int terminal_putchar(char c) terminal_new_line(); if (!isprint(c)) return 1; - /* if (c == ' ') { */ - /* for (size_t cy = 0; cy < 13; cy++) */ - /* for (size_t cx = 0; cx < 13; cx++) */ - /* put_pixel(0, screen->column + cx, */ - /* screen->row + cy); */ - /* } else { */ screen->buffer[screen->column + screen->row * VGA_WIDTH] = c; terminal_putentryat(get_font_node(c), screen->fg_color, screen->bg_color, screen->column * FONT_SIZE, screen->row * FONT_SIZE); if (++screen->column == VGA_WIDTH) terminal_new_line(); - /* } */ return 1; } @@ -291,7 +274,8 @@ void set_color_level(int level) VGA_COLOR_RED, VGA_COLOR_MAGENTA, VGA_COLOR_LIGHT_YELLOW, VGA_COLOR_LIGHT_YELLOW, VGA_COLOR_LIGHT_BLUE, VGA_COLOR_GREEN, - VGA_COLOR_LIGHT_GREY}; + VGA_COLOR_LIGHT_GREY, + }; if (level == 0) { terminal_set_color(screen->default_color, 0);