diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs index 44ea3cb1b..04dbf46da 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs @@ -7,7 +7,6 @@ using System.Collections.ObjectModel; using System.Management.Automation; using System.Management.Automation.Host; -using System.Reflection; using System.Security; using System.Threading; using Microsoft.Extensions.Logging; @@ -21,8 +20,6 @@ internal class EditorServicesConsolePSHostUserInterface : PSHostUserInterface private readonly PSHostUserInterface _underlyingHostUI; - private readonly PSHostUserInterface _consoleHostUI; - /// /// We use a ConcurrentDictionary because ConcurrentHashSet does not exist, hence the value /// is never actually used, and `WriteProgress` must be thread-safe. @@ -37,58 +34,19 @@ public EditorServicesConsolePSHostUserInterface( _readLineProvider = readLineProvider; _underlyingHostUI = underlyingHostUI; RawUI = new EditorServicesConsolePSHostRawUserInterface(loggerFactory, underlyingHostUI.RawUI); - - _consoleHostUI = GetConsoleHostUI(_underlyingHostUI); - - if (_consoleHostUI != null) - { - SetConsoleHostUIToInteractive(_consoleHostUI); - } } public override bool SupportsVirtualTerminal => _underlyingHostUI.SupportsVirtualTerminal; public override PSHostRawUserInterface RawUI { get; } - public override Dictionary Prompt(string caption, string message, Collection descriptions) - { - if (_consoleHostUI != null) - { - return _consoleHostUI.Prompt(caption, message, descriptions); - } + public override Dictionary Prompt(string caption, string message, Collection descriptions) => _underlyingHostUI.Prompt(caption, message, descriptions); - return _underlyingHostUI.Prompt(caption, message, descriptions); - } + public override int PromptForChoice(string caption, string message, Collection choices, int defaultChoice) => _underlyingHostUI.PromptForChoice(caption, message, choices, defaultChoice); - public override int PromptForChoice(string caption, string message, Collection choices, int defaultChoice) - { - if (_consoleHostUI != null) - { - return _consoleHostUI.PromptForChoice(caption, message, choices, defaultChoice); - } - - return _underlyingHostUI.PromptForChoice(caption, message, choices, defaultChoice); - } + public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options) => _underlyingHostUI.PromptForCredential(caption, message, userName, targetName, allowedCredentialTypes, options); - public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options) - { - if (_consoleHostUI != null) - { - return _consoleHostUI.PromptForCredential(caption, message, userName, targetName, allowedCredentialTypes, options); - } - - return _underlyingHostUI.PromptForCredential(caption, message, userName, targetName, allowedCredentialTypes, options); - } - - public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName) - { - if (_consoleHostUI is not null) - { - return _consoleHostUI.PromptForCredential(caption, message, userName, targetName); - } - - return _underlyingHostUI.PromptForCredential(caption, message, userName, targetName); - } + public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName) => _underlyingHostUI.PromptForCredential(caption, message, userName, targetName); public override string ReadLine() => _readLineProvider.ReadLine.ReadLine(CancellationToken.None); @@ -138,19 +96,5 @@ public void ResetProgress() public override void WriteVerboseLine(string message) => _underlyingHostUI.WriteVerboseLine(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 is null) - { - return null; - } - - return (PSHostUserInterface)externalUIField.GetValue(ui); - } - - private static void SetConsoleHostUIToInteractive(PSHostUserInterface ui) => ui.GetType().GetProperty("ThrowOnReadAndPrompt", BindingFlags.NonPublic | BindingFlags.Instance)?.SetValue(ui, false); } }