From dbaa83c6e2ab26b2388fb1bdc7b514c402dbc7e8 Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Sat, 15 Jan 2022 17:20:13 -0500 Subject: [PATCH 1/2] Do not merge information stream into output This was causing an error where the formatting of the information streams was dropped, and so just rendered in plaintext. This code now operates the same was as in version 2.0, where we only merge the error stream into the output. --- src/PowerShellEditorServices/Utility/PSCommandExtensions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/PowerShellEditorServices/Utility/PSCommandExtensions.cs b/src/PowerShellEditorServices/Utility/PSCommandExtensions.cs index f671240ad..bc5a53d05 100644 --- a/src/PowerShellEditorServices/Utility/PSCommandExtensions.cs +++ b/src/PowerShellEditorServices/Utility/PSCommandExtensions.cs @@ -66,7 +66,6 @@ public static PSCommand MergePipelineResults(this PSCommand psCommand) // We need to do merge errors and output before rendering with an Out- cmdlet Command lastCommand = psCommand.Commands[psCommand.Commands.Count - 1]; lastCommand.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output); - lastCommand.MergeMyResults(PipelineResultTypes.Information, PipelineResultTypes.Output); } return psCommand; } From c2370635421e360418f13fdea80086de7dd4ea9b Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 13 Jan 2022 13:33:09 -0800 Subject: [PATCH 2/2] Add missing overrides in `EditorServicesConsolePSHostRawUserInterface` --- ...ditorServicesConsolePSHostUserInterface.cs | 67 ++++++------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs index cab60cfff..193f448a5 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using Microsoft.Extensions.Logging; -using Microsoft.PowerShell.EditorServices.Services.PowerShell.Console; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -11,13 +9,13 @@ using System.Reflection; using System.Security; using System.Threading; +using Microsoft.Extensions.Logging; +using Microsoft.PowerShell.EditorServices.Services.PowerShell.Console; namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Host { internal class EditorServicesConsolePSHostUserInterface : PSHostUserInterface { - private readonly ILogger _logger; - private readonly IReadLineProvider _readLineProvider; private readonly PSHostUserInterface _underlyingHostUI; @@ -29,22 +27,22 @@ public EditorServicesConsolePSHostUserInterface( IReadLineProvider readLineProvider, PSHostUserInterface underlyingHostUI) { - _logger = loggerFactory.CreateLogger(); _readLineProvider = readLineProvider; _underlyingHostUI = underlyingHostUI; RawUI = new EditorServicesConsolePSHostRawUserInterface(loggerFactory, underlyingHostUI.RawUI); _consoleHostUI = GetConsoleHostUI(_underlyingHostUI); + if (_consoleHostUI != null) { SetConsoleHostUIToInteractive(_consoleHostUI); } } - public override PSHostRawUserInterface RawUI { get; } - public override bool SupportsVirtualTerminal => _underlyingHostUI.SupportsVirtualTerminal; + public override PSHostRawUserInterface RawUI { get; } + public override Dictionary Prompt(string caption, string message, Collection descriptions) { if (_consoleHostUI != null) @@ -77,7 +75,7 @@ public override PSCredential PromptForCredential(string caption, string message, public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName) { - if (_consoleHostUI != null) + if (_consoleHostUI is not null) { return _consoleHostUI.PromptForCredential(caption, message, userName, targetName); } @@ -85,58 +83,37 @@ public override PSCredential PromptForCredential(string caption, string message, return _underlyingHostUI.PromptForCredential(caption, message, userName, targetName); } - public override string ReadLine() - { - return _readLineProvider.ReadLine.ReadLine(CancellationToken.None); - } + public override string ReadLine() => _readLineProvider.ReadLine.ReadLine(CancellationToken.None); - public override SecureString ReadLineAsSecureString() - { - return _readLineProvider.ReadLine.ReadSecureLine(CancellationToken.None); - } + public override SecureString ReadLineAsSecureString() => _readLineProvider.ReadLine.ReadSecureLine(CancellationToken.None); - public override void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value) - { - _underlyingHostUI.Write(foregroundColor, backgroundColor, value); - } + public override void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value) => _underlyingHostUI.Write(foregroundColor, backgroundColor, value); - public override void Write(string value) - { - _underlyingHostUI.Write(value); - } + public override void Write(string value) => _underlyingHostUI.Write(value); - public override void WriteDebugLine(string message) - { - _underlyingHostUI.WriteDebugLine(message); - } + public override void WriteDebugLine(string message) => _underlyingHostUI.WriteDebugLine(message); - public override void WriteErrorLine(string value) - { - _underlyingHostUI.WriteErrorLine(value); - } + public override void WriteErrorLine(string value) => _underlyingHostUI.WriteErrorLine(value); - public override void WriteLine(string value) - { - _underlyingHostUI.WriteLine(value); - } + public override void WriteInformation(InformationRecord record) => _underlyingHostUI.WriteInformation(record); + + public override void WriteLine() => _underlyingHostUI.WriteLine(); + + public override void WriteLine(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value) => _underlyingHostUI.WriteLine(foregroundColor, backgroundColor, value); + + public override void WriteLine(string value) => _underlyingHostUI.WriteLine(value); public override void WriteProgress(long sourceId, ProgressRecord record) => _underlyingHostUI.WriteProgress(sourceId, record); - public override void WriteVerboseLine(string message) - { - _underlyingHostUI.WriteVerboseLine(message); - } + public override void WriteVerboseLine(string message) => _underlyingHostUI.WriteVerboseLine(message); - public override void WriteWarningLine(string message) - { - _underlyingHostUI.WriteWarningLine(message); - } + public override void WriteWarningLine(string message) => _underlyingHostUI.WriteWarningLine(message); private static PSHostUserInterface GetConsoleHostUI(PSHostUserInterface ui) { FieldInfo externalUIField = ui.GetType().GetField("_externalUI", BindingFlags.NonPublic | BindingFlags.Instance); - if (externalUIField == null) + if (externalUIField is null) { return null; }