]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
diagnostics: Enable escape sequence processing on windows consoles
authorPeter Damianov <peter0x44@disroot.org>
Mon, 3 Jun 2024 17:07:08 +0000 (10:07 -0700)
committerJonathan Yong <10walls@gmail.com>
Sun, 16 Jun 2024 01:24:38 +0000 (01:24 +0000)
Since windows 10 release v1511, the windows console has had support for VT100
escape sequences. We should try to enable this, and utilize it where possible.

gcc/ChangeLog:
* diagnostic-color.cc (should_colorize): Enable processing of VT100
escape sequences on windows consoles

Signed-off-by: Peter Damianov <peter0x44@disroot.org>
gcc/diagnostic-color.cc

index cbe57ce763f2a5d4567fd65e2172cd7530166417..261a14b6c5f2168d2e42ff43aaa308901aafbffe 100644 (file)
@@ -300,12 +300,23 @@ should_colorize (void)
      pp_write_text_to_stream() in pretty-print.cc calls fputs() on
      that stream.  However, the code below for non-Windows doesn't seem
      to care about it either...  */
-  HANDLE h;
-  DWORD m;
+  HANDLE handle;
+  DWORD mode;
+  BOOL isconsole = false;
 
-  h = GetStdHandle (STD_ERROR_HANDLE);
-  return (h != INVALID_HANDLE_VALUE) && (h != NULL)
-         && GetConsoleMode (h, &m);
+  handle = GetStdHandle (STD_ERROR_HANDLE);
+
+  if ((handle != INVALID_HANDLE_VALUE) && (handle != NULL))
+    isconsole = GetConsoleMode (handle, &mode);
+
+  if (isconsole)
+    {
+      /* Try to enable processing of VT100 escape sequences */
+      mode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+      SetConsoleMode (handle, mode);
+    }
+
+  return isconsole;
 #else
   char const *t = getenv ("TERM");
   /* emacs M-x shell sets TERM="dumb".  */