[Bf-blender-cvs] [9bd10b1c921] master: CLog: Support colorized logging on windows

Ray Molenkamp noreply at git.blender.org
Thu Sep 10 19:31:15 CEST 2020


Commit: 9bd10b1c9218e65d9de57e9a95dd5d77d5b9243a
Author: Ray Molenkamp
Date:   Thu Sep 10 11:31:09 2020 -0600
Branches: master
https://developer.blender.org/rB9bd10b1c9218e65d9de57e9a95dd5d77d5b9243a

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

===================================================================

M	intern/clog/clog.c

===================================================================

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
 }



More information about the Bf-blender-cvs mailing list