From 238aac2dc76aa866b5172ba58be6088cc1ef4bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Pint=C3=A9r?= Date: Wed, 4 Dec 2024 00:59:52 +0100 Subject: [PATCH] Implement vprintf() contract properly --- main/kernel/Console.hpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/main/kernel/Console.hpp b/main/kernel/Console.hpp index bf8cf1a2..a3bda882 100644 --- a/main/kernel/Console.hpp +++ b/main/kernel/Console.hpp @@ -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;