fix: autocomplete working again (ratio starnakin) and clean some stuff

This commit is contained in:
0x35c 2024-12-19 11:03:09 +01:00
parent 4028372475
commit 61debdcb85
4 changed files with 682 additions and 51 deletions

View File

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

View File

@ -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];
};

View File

@ -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;

View File

@ -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);