From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by sourceware.org (Postfix) with ESMTPS id ADD313849AD2 for ; Thu, 9 May 2024 17:03:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADD313849AD2 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=disroot.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ADD313849AD2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=178.21.23.139 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715274189; cv=none; b=Y0JcvM0cmbX6t/Ns2QX3Jn8stRmPN5/y/XndKdM1ckFqqJzTgloM34MLCk/pa0zM5/RwYcgz8XTWy+fLr3793j4vhk8/QXT3qh5zTa+K3LwrdQOSgDYcAZyTJwFWbXsykjdvbwUKODaHSlQboWOQaMa1phuL1jX/u01wJMtx20w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715274189; c=relaxed/simple; bh=7l85+X/Bo1/LUScn9bygVgXIKyJiu7Yrgmriw2GJBC0=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=cvM4RWYwNH4waKDTgbfHf/yym8OT5pbIpbrvB6OGB4Q2u6uPN9ToFN2c56Gqb1pOHGbZH3fhSWdyELBVIrSd0C0t4SEvhz1XktqP+SUQledr/3bqEQKctSW6UVpDcYcu6WlzsuEE2HydC5b5tjWvRcA2WYKUTbQAl5T5WKGdeaw= ARC-Authentication-Results: i=1; server2.sourceware.org X-Virus-Scanned: SPAM Filter at disroot.org From: Peter Damianov DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1715274185; bh=7l85+X/Bo1/LUScn9bygVgXIKyJiu7Yrgmriw2GJBC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dhDCrXjlKAvyJ/IbElXS0vQWsXq/s/mtGM07wrHb9jnjVvQPl7BRIkKHUf8nLSjAC xvcZPJ3tr/CYSh6dWia5Egp2OYq4cLT2cS2pcV0hQDVPxULinB9a/o+5xjcsU3p/v6 NSuDG1cawuxaPoyhkBiSVKsFbK1ORzAsF727k9t9/tluavAJegkJAc1kt9HYBXDhYP ZN88xs761cpLRgX/Cfx7sJ3aNt4MMjDwf1io0dDfZxJhkBxejHOOJjiAegRWDHK/Y8 /Z8jAAS1aUz32A01Lllmv0h0hKsu/omfuXZjpHbZt5rSI7GHp/nGG7QBKsfpsA5rQL IGJ6Jgra1+72A== To: gcc-patches@gcc.gnu.org Cc: lh_mouse@126.com, pexu@pexu.org, Peter Damianov Subject: [PATCH v2 2/3] diagnostics: Don't hardcode auto_enable_urls to false for mingw hosts Date: Thu, 9 May 2024 10:01:58 -0700 Message-Id: <20240509170157.8534-2-peter0x44@disroot.org> In-Reply-To: <20240509170157.8534-1-peter0x44@disroot.org> References: <20240509170157.8534-1-peter0x44@disroot.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Windows terminal and mintty both have support for link escape sequences, and so auto_enable_urls shouldn't be hardcoded to false. For older versions of the windows console, mingw_ansi_fputs's console API translation logic does mangle these sequences, but there's nothing useful it could do even if this weren't the case, so check if the ansi escape sequences are supported at all. conhost.exe doesn't support link escape sequences, but printing them does not cause any problems. gcc/ChangeLog: * diagnostic-color.cc (auto_enable_urls): Don't hardcode to return false on mingw hosts. * diagnostic-color.cc (auto_enable_urls): Return true if console supports ansi escape sequences. Signed-off-by: Peter Damianov --- v2: auto_enable_urls should check if the console supports ansi escape sequences gcc/diagnostic-color.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gcc/diagnostic-color.cc b/gcc/diagnostic-color.cc index 3af198654af..03fe35b2dc8 100644 --- a/gcc/diagnostic-color.cc +++ b/gcc/diagnostic-color.cc @@ -293,9 +293,6 @@ parse_env_vars_for_urls () static bool auto_enable_urls () { -#ifdef __MINGW32__ - return false; -#else const char *term, *colorterm; /* First check the terminal is capable of printing color escapes, @@ -303,6 +300,21 @@ auto_enable_urls () if (!should_colorize ()) return false; +#ifdef __MINGW32__ + HANDLE handle; + DWORD mode; + + handle = GetStdHandle (STD_ERROR_HANDLE); + if ((handle == INVALID_HANDLE_VALUE) || (handle == NULL)) + return false; + + /* If ansi escape sequences aren't supported by the console, then URLs will + print mangled from mingw_ansi_fputs's console API translation. It wouldn't + be useful even if this weren't the case. */ + if (GetConsoleMode (handle, &mode) && !(mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)) + return false; +#endif + /* xfce4-terminal is known to not implement URLs at this time. Recently new installations (0.8) will safely ignore the URL escape sequences, but a large number of legacy installations (0.6.3) print @@ -337,7 +349,6 @@ auto_enable_urls () return false; return true; -#endif } /* Determine if URLs should be enabled, based on RULE, -- 2.39.2