Skip to content

Allow progress colors to be settable and gettable from the internal host #1272

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

Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -804,8 +804,8 @@ private void WriteDebuggerBanner(DebuggerStopEventArgs eventArgs)
internal ConsoleColor VerboseForegroundColor { get; set; } = ConsoleColor.Yellow;
internal ConsoleColor VerboseBackgroundColor { get; set; } = BackgroundColor;

internal ConsoleColor ProgressForegroundColor { get; set; } = ConsoleColor.Yellow;
internal ConsoleColor ProgressBackgroundColor { get; set; } = ConsoleColor.DarkCyan;
internal virtual ConsoleColor ProgressForegroundColor { get; set; } = ConsoleColor.Yellow;
internal virtual ConsoleColor ProgressBackgroundColor { get; set; } = ConsoleColor.DarkCyan;

private async Task StartReplLoopAsync(CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ internal class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface
{
#region Private Fields

private readonly PSHostUserInterface internalHostUI;
private ConsoleReadLine consoleReadLine;
private readonly PSHostUserInterface _internalHostUI;
private readonly PSObject _privateData;
private ConsoleReadLine _consoleReadLine;

#endregion

Expand All @@ -44,8 +45,9 @@ public TerminalPSHostUserInterface(
new TerminalPSHostRawUserInterface(logger, internalHost),
logger)
{
this.internalHostUI = internalHost.UI;
this.consoleReadLine = new ConsoleReadLine(powerShellContext);
_internalHostUI = internalHost.UI;
_privateData = internalHost.PrivateData;
_consoleReadLine = new ConsoleReadLine(powerShellContext);

// Set the output encoding to UTF-8 so that special
// characters are written to the console correctly
Expand All @@ -54,11 +56,11 @@ public TerminalPSHostUserInterface(
System.Console.CancelKeyPress +=
(obj, args) =>
{
if (!this.IsNativeApplicationRunning)
if (!IsNativeApplicationRunning)
{
// We'll handle Ctrl+C
args.Cancel = true;
this.SendControlC();
SendControlC();
}
};
}
Expand All @@ -70,6 +72,36 @@ public TerminalPSHostUserInterface(
/// </summary>
internal protected override bool SupportsWriteProgress => true;

/// <summary>
/// Gets and sets the value of progress foreground from the internal host since Progress is handled there.
/// </summary>
internal override ConsoleColor ProgressForegroundColor
{
get
{
return (ConsoleColor) _privateData.Properties["ProgressForegroundColor"].Value;
}
set
{
_privateData.Properties["ProgressForegroundColor"].Value = value;
}
}

/// <summary>
/// Gets and sets the value of progress background from the internal host since Progress is handled there.
/// </summary>
internal override ConsoleColor ProgressBackgroundColor
{
get
{
return (ConsoleColor) _privateData.Properties["ProgressBackgroundColor"].Value;
}
set
{
_privateData.Properties["ProgressBackgroundColor"].Value = value;
}
}

/// <summary>
/// Requests that the HostUI implementation read a command line
/// from the user to be executed in the integrated console command
Expand All @@ -81,7 +113,7 @@ public TerminalPSHostUserInterface(
/// <returns>A Task that can be awaited for the resulting input string.</returns>
protected override Task<string> ReadCommandLineAsync(CancellationToken cancellationToken)
{
return this.consoleReadLine.ReadCommandLineAsync(cancellationToken);
return _consoleReadLine.ReadCommandLineAsync(cancellationToken);
}

/// <summary>
Expand All @@ -92,9 +124,9 @@ protected override Task<string> ReadCommandLineAsync(CancellationToken cancellat
protected override InputPromptHandler OnCreateInputPromptHandler()
{
return new TerminalInputPromptHandler(
this.consoleReadLine,
_consoleReadLine,
this,
this.Logger);
Logger);
}

/// <summary>
Expand All @@ -105,9 +137,9 @@ protected override InputPromptHandler OnCreateInputPromptHandler()
protected override ChoicePromptHandler OnCreateChoicePromptHandler()
{
return new TerminalChoicePromptHandler(
this.consoleReadLine,
_consoleReadLine,
this,
this.Logger);
Logger);
}

/// <summary>
Expand Down Expand Up @@ -162,7 +194,7 @@ public override void WriteOutput(
/// </param>
protected override void WriteProgressImpl(long sourceId, ProgressRecord record)
{
this.internalHostUI.WriteProgress(sourceId, record);
_internalHostUI.WriteProgress(sourceId, record);
}

/// <summary>
Expand Down