[v2,3/3] pretty-print: Don't translate escape sequences to windows console API

Message ID 20240509170157.8534-3-peter0x44@disroot.org
State New
Headers
Series [v2,1/3] diagnostics: Enable escape sequence processing on windows consoles |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed

Commit Message

Peter0x44 May 9, 2024, 5:02 p.m. UTC
  Modern versions of windows (after windows 10 v1511) support VT100 escape
sequences, so translation for them is not necessary. The translation also
mangles embedded warning documentation links.

gcc/ChangeLog:
	* pretty-print.cc (mingw_ansi_fputs): Don't translate escape sequences if
	the console has ENABLE_VIRTUAL_TERMINAL_PROCESSING.

Signed-off-by: Peter Damianov <peter0x44@disroot.org>
---
 gcc/pretty-print.cc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

LIU Hao May 12, 2024, 9:59 a.m. UTC | #1
在 2024-05-10 01:02, Peter Damianov 写道:
> -  if (GetConsoleMode (h, &mode))
> -    /* If it is a console, translate ANSI escape codes as needed.  */
> +  if (GetConsoleMode (h, &mode) && !(mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING))
> +    /* If it is a console, and doesn't support ANSI escape codes, translate
> +     * them as needed.
> +     */

nitpicking: This should probably be

> +     * them as needed.  */


CC'ing Jonathan Yong. This series of patches look good to me.



-- 
Best regards,
LIU Hao
  

Patch

diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc
index eb59bf424b7..98b6410d6e4 100644
--- a/gcc/pretty-print.cc
+++ b/gcc/pretty-print.cc
@@ -674,8 +674,10 @@  mingw_ansi_fputs (const char *str, FILE *fp)
   /* Don't mess up stdio functions with Windows APIs.  */
   fflush (fp);
 
-  if (GetConsoleMode (h, &mode))
-    /* If it is a console, translate ANSI escape codes as needed.  */
+  if (GetConsoleMode (h, &mode) && !(mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING))
+    /* If it is a console, and doesn't support ANSI escape codes, translate
+     * them as needed.
+     */
     for (;;)
       {
 	if ((esc_code = find_esc_head (&prefix_len, &esc_head, read)) == 0)