[Libguestfs] [PATCH nbdkit v3 2/6] server: debug: Don't emit ANSI colour codes on Windows

Richard W.M. Jones
Tue, 09 May 2023 14:51:17 -0000

At least under Wine they are not recognized and you just see literal
"[0m" etc appearing in the output.

Updates: commit 5a011e02375912f2ad88de1ebc6d609e29d38f71
Reviewed-by: Laszlo Ersek <lersek at redhat.com>
---
 server/debug.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/server/debug.c b/server/debug.c
index 1b5ddaafe..2231d40a0 100644
--- a/server/debug.c
+++ b/server/debug.c
@@ -70,7 +70,9 @@ static void
 debug_common (bool in_server, const char *fs, va_list args)
 {
   int err = errno;
+#ifndef WIN32
   int tty;
+#endif
   CLEANUP_FREE char *str = NULL;
   size_t len = 0;
   FILE *fp;
@@ -88,15 +90,19 @@ debug_common (bool in_server, const char *fs, va_list args)
     return;
   }

+#ifndef WIN32
   tty = isatty (fileno (stderr));
   if (!in_server && tty) ansi_force_colour (ANSI_FG_BOLD_BLACK, fp);
+#endif

   prologue (fp);

   errno = err;
   vfprintf (fp, fs, args);

+#ifndef WIN32
   if (!in_server && tty) ansi_force_restore (fp);
+#endif
   fprintf (fp, "\n");
   close_memstream (fp);

--
2.39.2