fix: color change is now working

This commit is contained in:
0x35c
2025-11-03 18:32:20 +01:00
parent a0185690cb
commit 86ce44deff
5 changed files with 87 additions and 67 deletions

View File

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