From 9bd10b1c9218e65d9de57e9a95dd5d77d5b9243a Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Thu, 10 Sep 2020 11:31:09 -0600 Subject: [PATCH] CLog: Support colorized logging on windows When using Windows Terminal the same control codes Linux uses to colorize the text can be used. WT can be detected by looking at the WT_SESSION environment variable. Differential Revision: https://developer.blender.org/D8848 Reviewed by: campbellbarton --- intern/clog/clog.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/intern/clog/clog.c b/intern/clog/clog.c index 17c9d49ee51..1cebd9f2099 100644 --- a/intern/clog/clog.c +++ b/intern/clog/clog.c @@ -548,6 +548,14 @@ static void CLG_ctx_output_set(CLogContext *ctx, void *file_handle) ctx->output = fileno(ctx->output_file); #if defined(__unix__) || defined(__APPLE__) ctx->use_color = isatty(ctx->output); +#elif defined(WIN32) + /* Windows Terminal supports color like the Linux terminals do while the standard console does + * not, the way to tell the two apart is to look at the WT_SESSION environment variable which + * will only be defined for Windows Terminal. */ + + /* getenv is used here rather than BLI_getenv since there are no benefits for using it in this + * context. */ + ctx->use_color = isatty(ctx->output) && getenv("WT_SESSION"); #endif }