From fea15fbd1fdb509ee69db79420c6cc10044b6b09 Mon Sep 17 00:00:00 2001 From: MichalPavlik Date: Thu, 19 Sep 2024 20:45:40 +0200 Subject: [PATCH] Fixes writing unwanted characters to console when TerminalLogger is created directly (#10678) Call method that tells Windows to allow VT-100 output processing whenever the TerminalLogger is instantiated, rather than only in the MSBuild CLI entrypoint `xmake.cs`. Fixes #10579. --- src/MSBuild/TerminalLogger/TerminalLogger.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/MSBuild/TerminalLogger/TerminalLogger.cs b/src/MSBuild/TerminalLogger/TerminalLogger.cs index bcae846e898..038ec536f6b 100644 --- a/src/MSBuild/TerminalLogger/TerminalLogger.cs +++ b/src/MSBuild/TerminalLogger/TerminalLogger.cs @@ -221,6 +221,8 @@ public ProjectContext(BuildEventContext context) /// private bool _showCommandLine = false; + private uint? _originalConsoleMode; + /// /// Default constructor, used by the MSBuild logger infra. /// @@ -263,6 +265,8 @@ public void Initialize(IEventSource eventSource, int nodeCount) /// public void Initialize(IEventSource eventSource) { + (_, _, _originalConsoleMode) = NativeMethodsShared.QueryIsScreenAndTryEnableAnsiColorCodes(); + ParseParameters(); eventSource.BuildStarted += BuildStarted; @@ -358,6 +362,8 @@ private bool TryApplyShowCommandLineParameter(string? parameterValue) /// public void Shutdown() { + NativeMethodsShared.RestoreConsoleMode(_originalConsoleMode); + _cts.Cancel(); _refresher?.Join(); Terminal.Dispose();