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
This commit is contained in:
Ray Molenkamp 2020-09-10 11:31:09 -06:00
parent 359acad5e4
commit 9bd10b1c92

@ -548,6 +548,14 @@ static void CLG_ctx_output_set(CLogContext *ctx, void *file_handle)
ctx->output = fileno(ctx->output_file); ctx->output = fileno(ctx->output_file);
#if defined(__unix__) || defined(__APPLE__) #if defined(__unix__) || defined(__APPLE__)
ctx->use_color = isatty(ctx->output); 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 #endif
} }