feature: log level on kprintf (color)

fix: kprintf now uses concatenated strings for the flag
This commit is contained in:
2024-09-20 12:40:36 +02:00
parent 4cc1dba5f9
commit 2e41858c77
13 changed files with 99 additions and 81 deletions

View File

@ -1,11 +1,15 @@
#include "ctype.h"
#include "kprintf.h"
#include "stdlib.h"
#include "string.h"
#include "terminal.h"
#include <stdarg.h>
static int get_level(const char *str)
{
if (!str || !isdigit(str[0]))
return 8;
return str[0] - '0';
}
static int print_flag(char flag, va_list *ap)
{
switch (flag) {
@ -23,12 +27,15 @@ static int print_flag(char flag, va_list *ap)
return 0;
}
int kvprintf(int level, const char *restrict format, va_list ap)
int kvprintf(const char *restrict format, va_list ap)
{
const char *start = format;
int ret = 0;
(void)level;
int level = get_level(format);
set_color_level(level);
if (level != 8)
start++;
while (*start != '\0') {
if (*start == '%' && *(start + 1) != '\0') {
ret += print_flag(*(start + 1), &ap);
@ -38,6 +45,7 @@ int kvprintf(int level, const char *restrict format, va_list ap)
}
start++;
}
set_color_level(8);
update_cursor();
return ret;
}