From patchwork Thu May 9 16:57:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter0x44 X-Patchwork-Id: 1933504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=AoZv9Zom; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VZyrQ2t37z20fc for ; Fri, 10 May 2024 02:58:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3ED838449C0 for ; Thu, 9 May 2024 16:58:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by sourceware.org (Postfix) with ESMTPS id 5059D3858D39 for ; Thu, 9 May 2024 16:57:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5059D3858D39 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 5059D3858D39 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=1715273869; cv=none; b=tchbNXCVna+kG1isRvivjL1G76BccxV+MD4EkHmtS/XgCQiQLhTNbfC/dymKLMFqtzYcmRiFyRJ0rAgpinXnaee5GMK+6vIiLgCftR6/pD2eBtOxtCMHSvWFgGzkm4us1FlYLjHkxNLbKpVAtlCBCDbpoyl5a2R2UXKZhY+zuiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715273869; c=relaxed/simple; bh=E3SENEvNGDO3Iql01qOzP9bwxE6qFDxmHYYZ+spOszU=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=TPrygDN7uHXU5zmHJI5lM1+cByyimLl6B2IUJaRW9G6bYDG+/3x+UrPBcxBA0YhDisFD7EOJVr/WP8iJ4T7nLVj8vWroSzS2LMBG6hceAu8jGMBzs0VJaWkhNX1czKPC+aVPYokRjsIDyMPzs87bdPE3SE7V8TOL22nY0mrkrAw= 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=1715273865; bh=E3SENEvNGDO3Iql01qOzP9bwxE6qFDxmHYYZ+spOszU=; h=From:To:Cc:Subject:Date; b=AoZv9ZomsumZVkpiUw4oEs34Dw/aq8mtIUYjRi32LJrG+nzff4Xcqf0S0Lp9tSUbQ IcWp3qC587Ypa/cBi4eh4cFeDhtnpNIGTAbHqam6Jtiw8kNxSy+NKFKxpa6KEh80Jr dY016xnORCotD/vhxYopiiXuJz+jjr3kmJEJEIcArhzR020E7tlfD0TJyY58+g/jd2 Mx23zY0UdhhvwewM7RDLcqadj8zv4YRuJ1SgP0mQkU35jiuw3RufBe9b/k5iOyXTaV ZLUSY8se9NR4lmQY/Oo7cfnW6bsESKfc9ULmiAQtg/xkPUHNkCf2OoLwEG+eRomfLh zKPM0l4Y9MLAw== To: gcc-patches@gcc.gnu.org Cc: lh_mouse@126.com, pexu@pexu.org, Peter Damianov Subject: [PATCH 1/3] diagnostics: Enable escape sequence processing on windows consoles Date: Thu, 9 May 2024 09:57:16 -0700 Message-Id: <20240509165717.7319-1-peter0x44@disroot.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 --- 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". */ From patchwork Thu May 9 16:57:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter0x44 X-Patchwork-Id: 1933503 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=aFFvllyl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VZyrR0CVRz214K for ; Fri, 10 May 2024 02:58:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 335003846013 for ; Thu, 9 May 2024 16:58:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by sourceware.org (Postfix) with ESMTPS id DA1BB385840D for ; Thu, 9 May 2024 16:57:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA1BB385840D 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 DA1BB385840D 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=1715273872; cv=none; b=etGVK/2HMHTHHvHO0xWn7kAmv+dy0A2YrP6o9e7e18w2ysoyPSpX0PlQafDPHeH3HTno2iHW/Md/HKlaUf7M2kjtDjLxkkH/MVNgmXt5/u4xhEHUKJS9qjR087/mm4M4U18w2Cuic7sHU5Tv9ybCzW72WeKkcYEPsI3VZF8zsac= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715273872; c=relaxed/simple; bh=qm6EdLqIx5nhq6b+9SYg5V0vjfKuYGggoL2bej1G04E=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=k1xkQKAwGANLxwQGMDrYi3OBDanyuCuiNRTmQR2RIEDfOMoM6iWQ0LQHagj5AxdneB2NkUB25w78ZBtYFXOSuC7TlX4v0VGsuZmd47PRmWnuDe28idaNY306pU5ixfdtex0KIxNPkYi8t9LINnu8zWZd73WXmU8gY99KVRYlxWU= 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=1715273867; bh=qm6EdLqIx5nhq6b+9SYg5V0vjfKuYGggoL2bej1G04E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aFFvllyl2qDidUOJitj4Lrj5S3HY2rCofukXsA4Myp5n15P/+SuW+RSS7YAzDtxll peu4nBubkmM2YcUNIhe7JHkL2cT+ouivkB0UGNlXu8pYsjfD6VaeBRwjjFXV2f1ZKl NgoennbrF4PJRd57N2EnRgYoJqXbam3ieKd15mpXGVgdjyij4FDXP1cd053KxsQS7Q sJsXfenrWm7FZsdSGVNZnK5gfc0gPA/RJLxtoswafIgdQr9eV+IVx2zaa1wuvmi2be Qs0V4jVTmYbHjtSf9GgIFy/8sxf8l5iVwSo3zlVoJ4nBwZrGniG4UJAMIme/R++0kB VIkMoay7ERtqQ== To: gcc-patches@gcc.gnu.org Cc: lh_mouse@126.com, pexu@pexu.org, Peter Damianov Subject: [PATCH 2/3] diagnostics: Don't hardcode auto_enable_urls to false for mingw hosts Date: Thu, 9 May 2024 09:57:17 -0700 Message-Id: <20240509165717.7319-2-peter0x44@disroot.org> In-Reply-To: <20240509165717.7319-1-peter0x44@disroot.org> References: <20240509165717.7319-1-peter0x44@disroot.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 --- 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, From patchwork Thu May 9 16:57:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter0x44 X-Patchwork-Id: 1933505 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=aEoSw8Im; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VZyrb6Fqxz20fc for ; Fri, 10 May 2024 02:58:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16881384474A for ; Thu, 9 May 2024 16:58:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by sourceware.org (Postfix) with ESMTPS id 434E13858410 for ; Thu, 9 May 2024 16:57:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 434E13858410 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 434E13858410 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=1715273872; cv=none; b=fwNm4YZqixLS5+TDRhs7L5POeZ7t5PfCyBczqb61/OoSnZzAEq++LEHXbR8c5bgqrPSeJb4+DXckTP6Qvmad6LVa16WLe4pdmYqWTgE06qdgbeYNmf4HLFR7LHMfLZ3vMXkKJ4/xmlt/VsL12AfQ2b3VhEj+KQneP/3sH8BxsaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715273872; c=relaxed/simple; bh=UDA5yKq6q/xwUB/uj6DLXw/wIRutAmnnYSlc1Um+xVw=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=dDCwoHPgIZ+uSFry8rlKKBlZGyOBu6VSK4LHYByQ/wjZLdi1/dGDUmGuMzavNAJU87moXT7e9/gW6DkXC/OUDZ0PX65r7qVv2g5rnUVN0XwPFgNUX1ATpybWg0w+aTK0n4H16ky+rlb1V19fyECblr33cISkhbX0ZHNEbIV1/S8= 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=1715273868; bh=UDA5yKq6q/xwUB/uj6DLXw/wIRutAmnnYSlc1Um+xVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aEoSw8Im0n65nPBchJ0UiiTX6fA0gw7H6BoDuCb3kJgZ5O0jRUl23oVWRCVnspQX7 laJ7HEYxL9GV+xIZbOm5QRA2ubc+MxEhRQzyMyHAWbaMD1aBu+Q0vfQyyRdH9y/Vzy 0uz7Ywd3HcU+5jFDc7JKAf6g44xrqmZI1drVcMs3i/RvBNCHjdcZg9ByrA8u28m2hw HvahtHuXOrwlonD58vLJ4RyTB0YuE02rczDrM5w/Scwj3C0EfTdNFdGSp+WuGJhGOL GMCauVIj9YwDsz2Px3aZn5sdXRBlByJCnQG+TdioUEhD/97GxJTELtVkiGWRg48RSW AOmfRXmeZ4l9g== To: gcc-patches@gcc.gnu.org Cc: lh_mouse@126.com, pexu@pexu.org, Peter Damianov Subject: [PATCH 3/3] pretty-print: Don't translate escape sequences to windows console API Date: Thu, 9 May 2024 09:57:18 -0700 Message-Id: <20240509165717.7319-3-peter0x44@disroot.org> In-Reply-To: <20240509165717.7319-1-peter0x44@disroot.org> References: <20240509165717.7319-1-peter0x44@disroot.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 --- gcc/pretty-print.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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)