Skip to content

Add missing overrides in EditorServicesConsolePSHostRawUserInterface #1665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -29,22 +27,22 @@ public EditorServicesConsolePSHostUserInterface(
IReadLineProvider readLineProvider,
PSHostUserInterface underlyingHostUI)
{
_logger = loggerFactory.CreateLogger<EditorServicesConsolePSHostUserInterface>();
_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<string, PSObject> Prompt(string caption, string message, Collection<FieldDescription> descriptions)
{
if (_consoleHostUI != null)
Expand Down Expand Up @@ -77,66 +75,45 @@ 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);
}

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;
}
Expand Down