wip: fix the color change

This commit is contained in:
0x35c
2025-11-03 17:44:48 +01:00
parent 8496c78732
commit a0185690cb
2 changed files with 21 additions and 12 deletions

View File

@ -4,22 +4,31 @@
#include "utils.h" #include "utils.h"
#include <stdint.h> #include <stdint.h>
struct color {
char *name;
int value;
};
void color_cmd(char *arg) void color_cmd(char *arg)
{ {
uint8_t tmp_color; uint8_t tmp_color;
static const char *colors[] = { static const struct color colors[] = {
"BLACK", "BLUE", "GREEN", "CYAN", {"BLACK", 0x000000}, {"BLUE", 0x0000FF},
"RED", "MAGENTA", "BROWN", "LIGHT_GREY", {"GREEN", 0x008000}, {"CYAN", 0x00FFFF},
"DARK_GREY", "LIGHT_BLUE", "LIGHT_GREEN", "LIGHT_CYAN", {"RED", 0xFF0000}, {"MAGENTA", 0xFF00FF},
"LIGHT_RED", "LIGHT_MAGENTA", "LIGHT_YELLOW", "WHITE", {"BROWN", 0xA52A2A}, {"LIGHT_GREY", 0xD3D3D3},
}; {"DARK_GREY", 0x555555}, {"LIGHT_BLUE", 0xADD8E6},
{"LIGHT_GREEN", 0x90EE90}, {"LIGHT_CYAN", 0xE0FFFF},
{"LIGHT_RED", 0xFF6666}, {"LIGHT_MAGENTA", 0xFF77FF},
{"LIGHT_YELLOW", 0xFFFFE0}, {"WHITE", 0xFFFFFF}};
if (!arg) if (!arg)
goto invalid; goto invalid;
for (size_t i = 0; i < ARRAY_SIZE(colors); i++) { for (size_t i = 0; i < ARRAY_SIZE(colors); i++) {
if (strcmp(colors[i], arg) == 0) { if (strcmp(colors[i].name, arg) == 0) {
terminal_set_fg_color(i); terminal_set_fg_color(colors[i].value);
terminal_refresh_color(); kprintf("color: %s\n", colors[i].name);
// terminal_refresh_color();
return; return;
} }
} }
@ -28,8 +37,8 @@ invalid:
kprintf(KERN_WARNING "Invalid argument\n"); kprintf(KERN_WARNING "Invalid argument\n");
kprintf("Available colors: "); kprintf("Available colors: ");
for (size_t i = 0; i < ARRAY_SIZE(colors); i++) { for (size_t i = 0; i < ARRAY_SIZE(colors); i++) {
terminal_set_default_fg_color(i); terminal_set_default_fg_color(colors[i].value);
kprintf(colors[i]); kprintf(colors[i].name);
if (i != ARRAY_SIZE(colors) - 1) if (i != ARRAY_SIZE(colors) - 1)
kprintf(", "); kprintf(", ");
} }

View File

@ -147,7 +147,7 @@ static void terminal_new_line(void)
void terminal_refresh_color(void) void terminal_refresh_color(void)
{ {
terminal_clear(); // terminal_clear();
for (uint32_t y = 0; y < VGA_HEIGHT; y++) for (uint32_t y = 0; y < VGA_HEIGHT; y++)
for (uint32_t x = 0; x < VGA_WIDTH; x++) for (uint32_t x = 0; x < VGA_WIDTH; x++)
terminal_putentryat( terminal_putentryat(