From 0a181d8c3dd43458e87513ae441bc41784278f11 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 14 Nov 2022 21:51:53 -0800 Subject: [PATCH] Separate color being supported from being enabled Previously, we were using `color_enabled` to mean both that the color was supported and that it was enabled by the user (which it is enabled by default). But this logic doesn't work well if the color check function is called again and ends up enabling color after the user disabled it. To fix this, just separate the two so the user controls one `color_supported` variable and the `color_enabled` variable is separate. Check both of them in order to print color, of course. --- desktop_version/src/Vlogging.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/Vlogging.c b/desktop_version/src/Vlogging.c index 666b612b..79041caf 100644 --- a/desktop_version/src/Vlogging.c +++ b/desktop_version/src/Vlogging.c @@ -16,7 +16,7 @@ # define STDERR_IS_TTY 0 #endif -#define COLOR(EXPR) color_enabled ? EXPR : "" +#define COLOR(EXPR) (color_enabled && color_supported ? EXPR : "") #define Color_RESET COLOR("\x1b[0m") #define Color_BOLD COLOR("\x1b[1m") @@ -25,7 +25,8 @@ #define Color_BOLD_GRAY COLOR("\x1b[1;90m") static int output_enabled = 1; -static int color_enabled = 0; +static int color_supported = 0; +static int color_enabled = 1; static int debug_enabled = 0; static int info_enabled = 1; static int warn_enabled = 1; @@ -35,7 +36,7 @@ static void check_color_support(void) { if (STDOUT_IS_TTY && STDERR_IS_TTY) { - color_enabled = 1; + color_supported = 1; } }