From 542f2e029717f068b9707b5316d36fb805008e5d Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 14 Apr 2023 21:13:30 +0200 Subject: [PATCH] Fix color codes --- core_compiler.cpp | 1 - core_compiler.h | 1 - core_parsing.cpp | 4 ++-- info.bat | 1 + os_windows.cpp | 2 ++ 5 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 info.bat diff --git a/core_compiler.cpp b/core_compiler.cpp index 18caa71..d65ae68 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -16,7 +16,6 @@ static void core_init_compiler(Core_Ctx *ctx, Allocator *allocator) { ctx->emit_type_info = true; ctx->emit_line_directives = false; ctx->debugger_break_on_compiler_error = true; - ctx->color_codes_enabled = true; ctx->same_scope_token = {SAME_SCOPE}; arena_init(&ctx->perm_push_only, "Perm Push Only"_s); diff --git a/core_compiler.h b/core_compiler.h index a5145c5..867bfc1 100644 --- a/core_compiler.h +++ b/core_compiler.h @@ -71,7 +71,6 @@ struct Core_Ctx { F64 start; } time; - bool color_codes_enabled; bool debugger_break_on_compiler_error; // Codegen stage mostly diff --git a/core_parsing.cpp b/core_parsing.cpp index aaac50f..4e95e8e 100644 --- a/core_parsing.cpp +++ b/core_parsing.cpp @@ -82,7 +82,7 @@ static void compiler_error(Token *token1, Token *token2, const char *str, ...) { STRING_FMT(pctx->perm, str, string); Core_Message *msg = core_add_message(CORE_ERROR, string, token1, token2); if (pctx->debugger_break_on_compiler_error) { - String str = core_stringify_message(pctx, pctx->perm, msg, pctx->color_codes_enabled); + String str = core_stringify_message(pctx, pctx->perm, msg, GLOBAL_EnabledConsoleColors); printf("%s", str.str); // @! How to get rid of printf ? fflush(stdout); Breakpoint; @@ -94,7 +94,7 @@ compiler_error(Token *token, const char *str, ...) { STRING_FMT(pctx->perm, str, string); Core_Message *msg = core_add_message(CORE_ERROR, string, token); if (pctx->debugger_break_on_compiler_error) { - String str = core_stringify_message(pctx, pctx->perm, msg, pctx->color_codes_enabled); + String str = core_stringify_message(pctx, pctx->perm, msg, GLOBAL_EnabledConsoleColors); printf("%s", str.str); // @! How to get rid of printf ? fflush(stdout); Breakpoint; diff --git a/info.bat b/info.bat new file mode 100644 index 0000000..a3ee798 --- /dev/null +++ b/info.bat @@ -0,0 +1 @@ +cloc *.hpp *.cpp *.py *.h \ No newline at end of file diff --git a/os_windows.cpp b/os_windows.cpp index b37f3be..b987cf1 100644 --- a/os_windows.cpp +++ b/os_windows.cpp @@ -215,6 +215,7 @@ os_list_dir(Arena *scratch, Allocator *a, String dir, U32 flags = LIST_NO_FLAGS) return result; } +bool GLOBAL_EnabledConsoleColors; bool os_enable_console_colors() { // Set output mode to handle virtual terminal sequences HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); @@ -223,6 +224,7 @@ bool os_enable_console_colors() { if (GetConsoleMode(hOut, &dwMode)) { dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; if (SetConsoleMode(hOut, dwMode)) { + GLOBAL_EnabledConsoleColors = true; return true; } else {