public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] diagnostics: Enable escape sequence processing on windows consoles
@ 2024-05-09 17:01 Peter Damianov
  2024-05-09 17:01 ` [PATCH v2 2/3] diagnostics: Don't hardcode auto_enable_urls to false for mingw hosts Peter Damianov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Peter Damianov @ 2024-05-09 17:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: lh_mouse, pexu, Peter Damianov

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>
---

Forgot to add -v2 to git send-email the first time I sent. Sorry for the spam.

 gcc/diagnostic-color.cc | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/gcc/diagnostic-color.cc b/gcc/diagnostic-color.cc
index f01a0fc2e37..3af198654af 100644
--- a/gcc/diagnostic-color.cc
+++ b/gcc/diagnostic-color.cc
@@ -213,12 +213,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".  */
-- 
2.39.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-05-13 12:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-09 17:01 [PATCH v2 1/3] diagnostics: Enable escape sequence processing on windows consoles Peter Damianov
2024-05-09 17:01 ` [PATCH v2 2/3] diagnostics: Don't hardcode auto_enable_urls to false for mingw hosts Peter Damianov
2024-05-13 12:30   ` NightStrike
2024-05-13 12:36     ` Peter0x44
2024-05-09 17:02 ` [PATCH v2 3/3] pretty-print: Don't translate escape sequences to windows console API Peter Damianov
2024-05-12  9:59   ` LIU Hao
2024-05-11 23:37 ` [PATCH v2 1/3] diagnostics: Enable escape sequence processing on windows consoles Peter0x44

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).