Skip to content

Commit

Permalink
Implement vprintf() contract properly
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Dec 4, 2024
1 parent d871ecf commit 238aac2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions main/kernel/Console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,37 @@ class ConsoleProvider {
logRecords.offer(level, buffer);
}

int count = 0;
#ifdef FARMHUB_DEBUG
// Erase the current line
printf("\033[1G\033[0K");
count += printf("\033[1G\033[0K");
switch (level) {
case Level::Error:
printf(FARMHUB_LOG_COLOR(FARMHUB_LOG_COLOR_RED));
count += printf(FARMHUB_LOG_COLOR(FARMHUB_LOG_COLOR_RED));
break;
case Level::Warning:
printf(FARMHUB_LOG_COLOR(FARMHUB_LOG_COLOR_BROWN));
count += printf(FARMHUB_LOG_COLOR(FARMHUB_LOG_COLOR_BROWN));
break;
case Level::Info:
printf(FARMHUB_LOG_COLOR(FARMHUB_LOG_COLOR_GREEN));
count += printf(FARMHUB_LOG_COLOR(FARMHUB_LOG_COLOR_GREEN));
break;
default:
break;
}
#endif

int count = originalVprintf(format, args);
int originalCount = originalVprintf(format, args);
if (originalCount < 0) {
return originalCount;
}
count += originalCount;

#ifdef FARMHUB_DEBUG
switch (level) {
case Level::Error:
case Level::Warning:
case Level::Info:
printf(FARMHUB_LOG_RESET_COLOR);
count += printf(FARMHUB_LOG_RESET_COLOR);
break;
default:
break;
Expand Down

0 comments on commit 238aac2

Please sign in to comment.