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 0E4C73858D39 for ; Thu, 9 May 2024 17:02:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E4C73858D39 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 0E4C73858D39 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=1715274156; cv=none; b=j+r205z0+BRDs6LzYKiSHyIVPhd3kJT/ijqRtAX1Z32U+dIZFklCbnXbVWUN/75W14cRltpMSP0lalKvQvYontY438cGrfehJXmBNXVFmclIdB31uGgd7QInmnybv7V5TNOiDrZqdNH14Am0B/npBqC3RXsGtIUWGD5CyMJveQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715274156; c=relaxed/simple; bh=yunrqfaBrSewGaJg3NmLLYpyrriMO52k9OHGogYfVh8=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=bv6OXlTSLYPeV/LqnRH9ildnukzoq9xKKbolH+390FodHVjqnWN1vyfWMQ2lLmSeGs46WNgKtinndz7dLiA69KdwgOy+uyW6BgBQrUrLPLQGxwfXAVn9swibAnF9SRDQAF5AZjc/UlsXNCPQ4OA+i/CSEYeU8kT87/uGwWH+HQs= 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=1715274152; bh=yunrqfaBrSewGaJg3NmLLYpyrriMO52k9OHGogYfVh8=; h=From:To:Cc:Subject:Date; b=IHr44ZLW2aPlz1RoMfVTj15GwLyfHEOh2uUjdFkFSJpdY0Sr1Oi+o4FBbak8tsbl3 7i+IhbC50QGr1pAVR+WzlUNv3MD1abmVsgIfDHEHt+3Zv4b7Sa1+mNFUTEsPtP0y3T 4YpknuVF9UI8tHgKmRxZ5l3GY4yR2L8gKjqYrHwXJDAiZjeBnEp4FRJJlS2yW7VF6W jHPv5O72uQIU752mcL3vhCVBliyX86aak7KJ04ZZmyfbGGQocyGxCAl1cGonPdOj85 bYHqRV2RQaYEFCev+hpJCJFvWbWm/cZqtsdVUEOp0Jsp0imiClh9/AurVPh2L3+Oq2 aIxfJ5xUPz+8A== To: gcc-patches@gcc.gnu.org Cc: lh_mouse@126.com, pexu@pexu.org, Peter Damianov Subject: [PATCH v2 1/3] diagnostics: Enable escape sequence processing on windows consoles Date: Thu, 9 May 2024 10:01:56 -0700 Message-Id: <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: 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 --- 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