fix: color change is now working
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
#include "base.h"
|
||||
#include "color.h"
|
||||
#include "ctype.h"
|
||||
#include "terminal.h"
|
||||
|
||||
@ -7,6 +8,15 @@
|
||||
|
||||
int print_int_base(int64_t number, const char *prefix, const char *base);
|
||||
|
||||
static void set_color_level(int level)
|
||||
{
|
||||
static uint32_t levels[] = {
|
||||
BLACK, RED, RED, MAGENTA, LIGHT_YELLOW,
|
||||
LIGHT_YELLOW, LIGHT_BLUE, GREEN, LIGHT_GREY,
|
||||
};
|
||||
terminal_set_fg_color(levels[level]);
|
||||
}
|
||||
|
||||
static int get_level(const char *str)
|
||||
{
|
||||
if (!str || !isdigit(str[0]))
|
||||
@ -43,9 +53,11 @@ int kvprintf(const char *restrict format, va_list *ap)
|
||||
int ret = 0;
|
||||
|
||||
const int level = get_level(format);
|
||||
set_color_level(level);
|
||||
if (level)
|
||||
uint32_t old_color = terminal_get_fg_color();
|
||||
if (level) {
|
||||
set_color_level(level);
|
||||
start++;
|
||||
}
|
||||
while (*start != '\0') {
|
||||
if (*start == '%' && *(start + 1) != '\0') {
|
||||
ret += print_flag(*(start + 1), ap);
|
||||
@ -55,7 +67,7 @@ int kvprintf(const char *restrict format, va_list *ap)
|
||||
}
|
||||
start++;
|
||||
}
|
||||
set_color_level(0);
|
||||
terminal_set_fg_color(old_color);
|
||||
update_cursor();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1,47 +1,31 @@
|
||||
#include "color.h"
|
||||
#include "kprintf.h"
|
||||
#include "string.h"
|
||||
#include "terminal.h"
|
||||
#include "utils.h"
|
||||
#include <stdint.h>
|
||||
|
||||
struct color {
|
||||
char *name;
|
||||
int value;
|
||||
};
|
||||
|
||||
void color_cmd(char *arg)
|
||||
{
|
||||
uint8_t tmp_color;
|
||||
static const struct color colors[] = {
|
||||
{"BLACK", 0x000000}, {"BLUE", 0x0000FF},
|
||||
{"GREEN", 0x008000}, {"CYAN", 0x00FFFF},
|
||||
{"RED", 0xFF0000}, {"MAGENTA", 0xFF00FF},
|
||||
{"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)
|
||||
goto invalid;
|
||||
for (size_t i = 0; i < ARRAY_SIZE(colors); i++) {
|
||||
if (strcmp(colors[i].name, arg) == 0) {
|
||||
terminal_set_fg_color(colors[i].value);
|
||||
kprintf("color: %s\n", colors[i].name);
|
||||
// terminal_refresh_color();
|
||||
return;
|
||||
}
|
||||
}
|
||||
invalid:
|
||||
tmp_color = terminal_get_default_color();
|
||||
uint32_t tmp_color = terminal_get_fg_color();
|
||||
kprintf(KERN_WARNING "Invalid argument\n");
|
||||
kprintf("Available colors: ");
|
||||
for (size_t i = 0; i < ARRAY_SIZE(colors); i++) {
|
||||
terminal_set_default_fg_color(colors[i].value);
|
||||
terminal_set_fg_color(colors[i].value);
|
||||
kprintf(colors[i].name);
|
||||
if (i != ARRAY_SIZE(colors) - 1)
|
||||
kprintf(", ");
|
||||
}
|
||||
terminal_set_default_fg_color(tmp_color);
|
||||
terminal_set_fg_color(tmp_color);
|
||||
kprintf("\n");
|
||||
}
|
||||
|
||||
@ -26,8 +26,7 @@ void terminal_initialize(void)
|
||||
for (int i = 0; i < TERM_COUNT; i++) {
|
||||
screens[i].row = 0;
|
||||
screens[i].column = 0;
|
||||
screens[i].default_color = 0;
|
||||
screens[i].fg_color = screens[i].default_color;
|
||||
screens[i].fg_color = 0;
|
||||
screens[i].bg_color = 0x8acd01;
|
||||
// screens[i].background = &image_icon;
|
||||
screens[i].font = consolas_regular_13_font;
|
||||
@ -86,22 +85,22 @@ void terminal_set_fg_color(uint32_t fg_color)
|
||||
screen->fg_color = fg_color;
|
||||
}
|
||||
|
||||
uint32_t terminal_get_bg_color(void)
|
||||
{
|
||||
return screen->bg_color;
|
||||
}
|
||||
|
||||
uint32_t terminal_get_fg_color(void)
|
||||
{
|
||||
return screen->fg_color;
|
||||
}
|
||||
|
||||
void terminal_set_color(uint32_t fg_color, uint32_t bg_color)
|
||||
{
|
||||
screen->fg_color = fg_color;
|
||||
screen->bg_color = bg_color;
|
||||
}
|
||||
|
||||
void terminal_set_default_fg_color(uint32_t fg_color)
|
||||
{
|
||||
screen->default_color = fg_color;
|
||||
}
|
||||
|
||||
uint32_t terminal_get_default_color(void)
|
||||
{
|
||||
return screen->default_color;
|
||||
}
|
||||
|
||||
uint8_t terminal_get_char(int x, int y)
|
||||
{
|
||||
return screen->buffer[y * VGA_WIDTH + x];
|
||||
@ -145,15 +144,16 @@ static void terminal_new_line(void)
|
||||
terminal_scroll();
|
||||
}
|
||||
|
||||
void terminal_refresh_color(void)
|
||||
{
|
||||
// terminal_clear();
|
||||
for (uint32_t y = 0; y < VGA_HEIGHT; y++)
|
||||
for (uint32_t x = 0; x < VGA_WIDTH; x++)
|
||||
terminal_putentryat(
|
||||
get_font_node(screen->buffer[y * VGA_WIDTH + x]),
|
||||
screen->fg_color, x, y);
|
||||
}
|
||||
// TODO
|
||||
// void terminal_refresh_color(void)
|
||||
// {
|
||||
// // terminal_clear();
|
||||
// for (uint32_t y = 0; y < VGA_HEIGHT; y++)
|
||||
// for (uint32_t x = 0; x < VGA_WIDTH; x++)
|
||||
// terminal_putentryat(
|
||||
// get_font_node(screen->buffer[y * VGA_WIDTH + x]),
|
||||
// screen->fg_color, x, y);
|
||||
// }
|
||||
|
||||
void terminal_clear(void)
|
||||
{
|
||||
@ -235,20 +235,3 @@ void move_cursor(int direction)
|
||||
}
|
||||
update_cursor();
|
||||
}
|
||||
|
||||
void set_color_level(int level)
|
||||
{
|
||||
int color_translation[] = {
|
||||
VGA_COLOR_WHITE, VGA_COLOR_RED,
|
||||
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,
|
||||
};
|
||||
|
||||
if (level == 0) {
|
||||
terminal_set_color(screen->default_color, screen->bg_color);
|
||||
return;
|
||||
}
|
||||
terminal_set_fg_color(color_translation[level]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user