From f08db4f520570ca05752702e3095bb0cb58acbba Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 27 Apr 2020 11:28:49 -0700 Subject: [PATCH 1/6] Allow progress colors to be settable and gettable from internal host --- .../Host/EditorServicesPSHostUserInterface.cs | 4 +-- .../Host/TerminalPSHostUserInterface.cs | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs index 0d7812b1e..e84e3340a 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs @@ -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) { diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs index 65043e38f..ea8f26f32 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs @@ -22,6 +22,7 @@ internal class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface #region Private Fields private readonly PSHostUserInterface internalHostUI; + private readonly PSObject _privateData; private ConsoleReadLine consoleReadLine; #endregion @@ -45,6 +46,7 @@ public TerminalPSHostUserInterface( logger) { this.internalHostUI = internalHost.UI; + _privateData = internalHost.PrivateData; this.consoleReadLine = new ConsoleReadLine(powerShellContext); // Set the output encoding to UTF-8 so that special @@ -70,6 +72,36 @@ public TerminalPSHostUserInterface( /// internal protected override bool SupportsWriteProgress => true; + /// + /// Gets and sets the value of progress foreground from the internal host since Progress is handled there. + /// + internal override ConsoleColor ProgressForegroundColor + { + get + { + return (ConsoleColor) _privateData.Properties["ProgressForegroundColor"].Value; + } + set + { + _privateData.Properties["ProgressForegroundColor"].Value = value; + } + } + + /// + /// Gets and sets the value of progress background from the internal host since Progress is handled there. + /// + internal override ConsoleColor ProgressBackgroundColor + { + get + { + return (ConsoleColor) _privateData.Properties["ProgressBackgroundColor"].Value; + } + set + { + _privateData.Properties["ProgressBackgroundColor"].Value = value; + } + } + /// /// Requests that the HostUI implementation read a command line /// from the user to be executed in the integrated console command From 954fd5aad2ebd10b1146fdbee47cd4451fc8f7c6 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 27 Apr 2020 11:33:08 -0700 Subject: [PATCH 2/6] cosmetic --- .../Host/TerminalPSHostUserInterface.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs index ea8f26f32..4bbced269 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs @@ -21,9 +21,9 @@ internal class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface { #region Private Fields - private readonly PSHostUserInterface internalHostUI; + private readonly PSHostUserInterface _internalHostUI; private readonly PSObject _privateData; - private ConsoleReadLine consoleReadLine; + private ConsoleReadLine _consoleReadLine; #endregion @@ -45,9 +45,9 @@ public TerminalPSHostUserInterface( new TerminalPSHostRawUserInterface(logger, internalHost), logger) { - this.internalHostUI = internalHost.UI; + _internalHostUI = internalHost.UI; _privateData = internalHost.PrivateData; - this.consoleReadLine = new ConsoleReadLine(powerShellContext); + _consoleReadLine = new ConsoleReadLine(powerShellContext); // Set the output encoding to UTF-8 so that special // characters are written to the console correctly @@ -56,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(); } }; } @@ -113,7 +113,7 @@ internal override ConsoleColor ProgressBackgroundColor /// A Task that can be awaited for the resulting input string. protected override Task ReadCommandLineAsync(CancellationToken cancellationToken) { - return this.consoleReadLine.ReadCommandLineAsync(cancellationToken); + return _consoleReadLine.ReadCommandLineAsync(cancellationToken); } /// @@ -124,9 +124,9 @@ protected override Task ReadCommandLineAsync(CancellationToken cancellat protected override InputPromptHandler OnCreateInputPromptHandler() { return new TerminalInputPromptHandler( - this.consoleReadLine, + _consoleReadLine, this, - this.Logger); + Logger); } /// @@ -137,9 +137,9 @@ protected override InputPromptHandler OnCreateInputPromptHandler() protected override ChoicePromptHandler OnCreateChoicePromptHandler() { return new TerminalChoicePromptHandler( - this.consoleReadLine, + _consoleReadLine, this, - this.Logger); + Logger); } /// @@ -194,7 +194,7 @@ public override void WriteOutput( /// protected override void WriteProgressImpl(long sourceId, ProgressRecord record) { - this.internalHostUI.WriteProgress(sourceId, record); + _internalHostUI.WriteProgress(sourceId, record); } /// From a0fd8c427306e5f8c8aee879ebf76dd6e35aa26a Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 27 Apr 2020 11:49:43 -0700 Subject: [PATCH 3/6] rename privatedata to a more descriptive name --- .../Session/Host/TerminalPSHostUserInterface.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs index 4bbced269..838ca9f93 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs @@ -22,7 +22,7 @@ internal class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface #region Private Fields private readonly PSHostUserInterface _internalHostUI; - private readonly PSObject _privateData; + private readonly PSObject _internalHostPrivateData; private ConsoleReadLine _consoleReadLine; #endregion @@ -46,7 +46,7 @@ public TerminalPSHostUserInterface( logger) { _internalHostUI = internalHost.UI; - _privateData = internalHost.PrivateData; + _internalHostPrivateData = internalHost.PrivateData; _consoleReadLine = new ConsoleReadLine(powerShellContext); // Set the output encoding to UTF-8 so that special @@ -79,11 +79,11 @@ internal override ConsoleColor ProgressForegroundColor { get { - return (ConsoleColor) _privateData.Properties["ProgressForegroundColor"].Value; + return (ConsoleColor) _internalHostPrivateData.Properties["ProgressForegroundColor"].Value; } set { - _privateData.Properties["ProgressForegroundColor"].Value = value; + _internalHostPrivateData.Properties["ProgressForegroundColor"].Value = value; } } @@ -94,11 +94,11 @@ internal override ConsoleColor ProgressBackgroundColor { get { - return (ConsoleColor) _privateData.Properties["ProgressBackgroundColor"].Value; + return (ConsoleColor) _internalHostPrivateData.Properties["ProgressBackgroundColor"].Value; } set { - _privateData.Properties["ProgressBackgroundColor"].Value = value; + _internalHostPrivateData.Properties["ProgressBackgroundColor"].Value = value; } } From f2f67249d1aca1b4a4eb127f9d2069602f87a6e0 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Mon, 27 Apr 2020 12:03:45 -0700 Subject: [PATCH 4/6] cleaner code Co-Authored-By: Patrick Meinecke --- .../Host/TerminalPSHostUserInterface.cs | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs index 838ca9f93..ec855b644 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs @@ -23,7 +23,7 @@ internal class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface private readonly PSHostUserInterface _internalHostUI; private readonly PSObject _internalHostPrivateData; - private ConsoleReadLine _consoleReadLine; + private readonly ConsoleReadLine _consoleReadLine; #endregion @@ -77,14 +77,8 @@ public TerminalPSHostUserInterface( /// internal override ConsoleColor ProgressForegroundColor { - get - { - return (ConsoleColor) _internalHostPrivateData.Properties["ProgressForegroundColor"].Value; - } - set - { - _internalHostPrivateData.Properties["ProgressForegroundColor"].Value = value; - } + get => (ConsoleColor)_privateData.Properties["ProgressForegroundColor"].Value; + set => _privateData.Properties["ProgressForegroundColor"].Value = value; } /// @@ -92,14 +86,8 @@ internal override ConsoleColor ProgressForegroundColor /// internal override ConsoleColor ProgressBackgroundColor { - get - { - return (ConsoleColor) _internalHostPrivateData.Properties["ProgressBackgroundColor"].Value; - } - set - { - _internalHostPrivateData.Properties["ProgressBackgroundColor"].Value = value; - } + get => (ConsoleColor)_internalHostPrivateData.Properties["ProgressBackgroundColor"].Value; + set => _internalHostPrivateData.Properties["ProgressBackgroundColor"].Value = value; } /// From 89bd867627e1c1072951f0cc23505ccf4b9f346d Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 27 Apr 2020 12:13:00 -0700 Subject: [PATCH 5/6] typo in suggestion --- .../Session/Host/TerminalPSHostUserInterface.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs index ec855b644..bbc17ba38 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs @@ -77,8 +77,8 @@ public TerminalPSHostUserInterface( /// internal override ConsoleColor ProgressForegroundColor { - get => (ConsoleColor)_privateData.Properties["ProgressForegroundColor"].Value; - set => _privateData.Properties["ProgressForegroundColor"].Value = value; + get => (ConsoleColor)_internalHostPrivateData.Properties["ProgressForegroundColor"].Value; + set => _internalHostPrivateData.Properties["ProgressForegroundColor"].Value = value; } /// From 9a3a4952aecfc9fd64ae323395cfbf2c71fa62c3 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 27 Apr 2020 13:09:44 -0700 Subject: [PATCH 6/6] change _internalHostUI back to internalHostUI to try to fix CI --- .../Session/Host/TerminalPSHostUserInterface.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs index bbc17ba38..6a3e7de0d 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs @@ -21,7 +21,7 @@ internal class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface { #region Private Fields - private readonly PSHostUserInterface _internalHostUI; + private readonly PSHostUserInterface internalHostUI; private readonly PSObject _internalHostPrivateData; private readonly ConsoleReadLine _consoleReadLine; @@ -45,7 +45,7 @@ public TerminalPSHostUserInterface( new TerminalPSHostRawUserInterface(logger, internalHost), logger) { - _internalHostUI = internalHost.UI; + internalHostUI = internalHost.UI; _internalHostPrivateData = internalHost.PrivateData; _consoleReadLine = new ConsoleReadLine(powerShellContext); @@ -182,7 +182,7 @@ public override void WriteOutput( /// protected override void WriteProgressImpl(long sourceId, ProgressRecord record) { - _internalHostUI.WriteProgress(sourceId, record); + internalHostUI.WriteProgress(sourceId, record); } ///