From e2a32aa6283aa81c6806bba0cf72b66963e56d95 Mon Sep 17 00:00:00 2001 From: GUIGHIL benjamin Date: Fri, 20 Apr 2018 00:55:37 +0200 Subject: [PATCH 1/4] Add customize output color enhancement (#651) Supress Warnings in travis Supress Warning in Travis #2 Test for travis Add Comment XML for travis Add Comment for Testing --- .travis.yml | 2 +- .../Session/Host/EditorServicesPSHost.cs | 160 +++++++++++++++++- .../Host/EditorServicesPSHostUserInterface.cs | 66 +++++++- 3 files changed, 219 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index d1611f7b9..1356e9224 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,4 +26,4 @@ install: script: - ulimit -n 4096 - - powershell -File scripts/travis.ps1 \ No newline at end of file + - powershell -File scripts/travis.ps1 diff --git a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs index d524396c6..a4ac86f67 100644 --- a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs +++ b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs @@ -6,6 +6,7 @@ using Microsoft.PowerShell.EditorServices.Session; using Microsoft.PowerShell.EditorServices.Utility; using System; +using System.Diagnostics.CodeAnalysis; using System.Management.Automation; using System.Management.Automation.Host; using System.Management.Automation.Runspaces; @@ -78,14 +79,165 @@ public override string Name } /// - /// + /// + /// + public class ConsoleColorProxy + { + private EditorServicesPSHostUserInterface _hostUserInterface; + + /// + /// + /// + public ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface) + { + if (hostUserInterface == null) throw new ArgumentNullException("hostUserInterface"); + _hostUserInterface = hostUserInterface; + } + + /// + /// + /// + public ConsoleColor ErrorForegroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.ErrorForegroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.ErrorForegroundColor = value; } + } + + /// + /// + /// + public ConsoleColor ErrorBackgroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.ErrorBackgroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.ErrorBackgroundColor = value; } + } + + /// + /// + /// + public ConsoleColor WarningForegroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.WarningForegroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.WarningForegroundColor = value; } + } + + /// + /// + /// + public ConsoleColor WarningBackgroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.WarningBackgroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.WarningBackgroundColor = value; } + } + + /// + /// + /// + public ConsoleColor DebugForegroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.DebugForegroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.DebugForegroundColor = value; } + } + + /// + /// + /// + public ConsoleColor DebugBackgroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.DebugBackgroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.DebugBackgroundColor = value; } + } + + /// + /// + /// + public ConsoleColor VerboseForegroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.VerboseForegroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.VerboseForegroundColor = value; } + } + + /// + /// + /// + public ConsoleColor VerboseBackgroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.VerboseBackgroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.VerboseBackgroundColor = value; } + } + + /// + /// + /// + public ConsoleColor ProgressForegroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.ProgressForegroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.ProgressForegroundColor = value; } + } + + /// + /// + /// + public ConsoleColor ProgressBackgroundColor + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + get + { return _hostUserInterface.ProgressBackgroundColor; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + set + { _hostUserInterface.ProgressBackgroundColor = value; } + } + } + + /// + /// Return the actual console host object so that the user can get at + /// the unproxied methods. /// public override PSObject PrivateData { - // There is no PrivateData yet but by returning an empty object we can get past PowerShell's - // check for $host.PrivateData["window"] which errors on the null returned by default. - get { return new PSObject(); } + get + { + if (hostUserInterface == null) return null; + return _consoleColorProxy ?? (_consoleColorProxy = PSObject.AsPSObject(new ConsoleColorProxy(hostUserInterface))); + } } + private PSObject _consoleColorProxy; /// /// diff --git a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs index e5006f0f7..a53aac17b 100644 --- a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs @@ -529,7 +529,8 @@ public override void WriteDebugLine(string message) DebugMessagePrefix + message, true, OutputType.Debug, - foregroundColor: ConsoleColor.Yellow); + foregroundColor: this.DebugForegroundColor, + backgroundColor: this.DebugBackgroundColor); } /// @@ -542,7 +543,8 @@ public override void WriteVerboseLine(string message) VerboseMessagePrefix + message, true, OutputType.Verbose, - foregroundColor: ConsoleColor.Blue); + foregroundColor: this.VerboseForegroundColor, + backgroundColor: this.VerboseBackgroundColor); } /// @@ -555,7 +557,8 @@ public override void WriteWarningLine(string message) WarningMessagePrefix + message, true, OutputType.Warning, - foregroundColor: ConsoleColor.Yellow); + foregroundColor: this.WarningForegroundColor, + backgroundColor: this.WarningBackgroundColor); } /// @@ -568,7 +571,8 @@ public override void WriteErrorLine(string value) value, true, OutputType.Error, - ConsoleColor.Red); + foregroundColor: this.ErrorForegroundColor, + backgroundColor: this.ErrorBackgroundColor); } /// @@ -684,6 +688,60 @@ private void WriteDebuggerBanner(DebuggerStopEventArgs eventArgs) } } + /// + /// + /// + public static ConsoleColor BackgroundColor + { + get; + set; + } + + /// + /// + /// + public ConsoleColor ErrorForegroundColor { get; set; } = ConsoleColor.Red; + /// + /// + /// + public ConsoleColor ErrorBackgroundColor { get; set; } = BackgroundColor; + + /// + /// + /// + public ConsoleColor WarningForegroundColor { get; set; } = ConsoleColor.Yellow; + /// + /// + /// + public ConsoleColor WarningBackgroundColor { get; set; } = BackgroundColor; + + /// + /// + /// + public ConsoleColor DebugForegroundColor { get; set; } = ConsoleColor.Yellow; + /// + /// + /// + public ConsoleColor DebugBackgroundColor { get; set; } = BackgroundColor; + + /// + /// + /// + public ConsoleColor VerboseForegroundColor { get; set; } = ConsoleColor.Yellow; + /// + /// + /// + public ConsoleColor VerboseBackgroundColor { get; set; } = BackgroundColor; + + /// + /// + /// + public ConsoleColor ProgressForegroundColor { get; set; } = ConsoleColor.Yellow; + /// + /// + /// + public ConsoleColor ProgressBackgroundColor { get; set; } = ConsoleColor.DarkCyan; + private async Task StartReplLoop(CancellationToken cancellationToken) { do From f210c8870042532b9cfa6120682ebd361a283e62 Mon Sep 17 00:00:00 2001 From: GUIGHIL benjamin Date: Fri, 20 Apr 2018 14:52:33 +0200 Subject: [PATCH 2/4] Adding internal class I added all internal class and suppress all the SuppressMessage. But I can't remove the empty documentation, the analysis of PowerShell Editor Services doesn't let it pass. I tried to add the suppress warning in it but it doesn't work as well. So I had to add all documentation. --- .../Session/Host/EditorServicesPSHost.cs | 25 ++---------------- .../Host/EditorServicesPSHostUserInterface.cs | 26 ++++++++----------- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs index a4ac86f67..89003ddba 100644 --- a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs +++ b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs @@ -6,7 +6,6 @@ using Microsoft.PowerShell.EditorServices.Session; using Microsoft.PowerShell.EditorServices.Utility; using System; -using System.Diagnostics.CodeAnalysis; using System.Management.Automation; using System.Management.Automation.Host; using System.Management.Automation.Runspaces; @@ -81,14 +80,14 @@ public override string Name /// /// /// - public class ConsoleColorProxy + internal class ConsoleColorProxy { private EditorServicesPSHostUserInterface _hostUserInterface; /// /// /// - public ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface) + internal ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface) { if (hostUserInterface == null) throw new ArgumentNullException("hostUserInterface"); _hostUserInterface = hostUserInterface; @@ -99,10 +98,8 @@ public ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface) /// public ConsoleColor ErrorForegroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.ErrorForegroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.ErrorForegroundColor = value; } } @@ -112,10 +109,8 @@ public ConsoleColor ErrorForegroundColor /// public ConsoleColor ErrorBackgroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.ErrorBackgroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.ErrorBackgroundColor = value; } } @@ -125,10 +120,8 @@ public ConsoleColor ErrorBackgroundColor /// public ConsoleColor WarningForegroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.WarningForegroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.WarningForegroundColor = value; } } @@ -138,10 +131,8 @@ public ConsoleColor WarningForegroundColor /// public ConsoleColor WarningBackgroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.WarningBackgroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.WarningBackgroundColor = value; } } @@ -151,10 +142,8 @@ public ConsoleColor WarningBackgroundColor /// public ConsoleColor DebugForegroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.DebugForegroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.DebugForegroundColor = value; } } @@ -164,10 +153,8 @@ public ConsoleColor DebugForegroundColor /// public ConsoleColor DebugBackgroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.DebugBackgroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.DebugBackgroundColor = value; } } @@ -177,10 +164,8 @@ public ConsoleColor DebugBackgroundColor /// public ConsoleColor VerboseForegroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.VerboseForegroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.VerboseForegroundColor = value; } } @@ -190,10 +175,8 @@ public ConsoleColor VerboseForegroundColor /// public ConsoleColor VerboseBackgroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.VerboseBackgroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.VerboseBackgroundColor = value; } } @@ -203,10 +186,8 @@ public ConsoleColor VerboseBackgroundColor /// public ConsoleColor ProgressForegroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.ProgressForegroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.ProgressForegroundColor = value; } } @@ -216,10 +197,8 @@ public ConsoleColor ProgressForegroundColor /// public ConsoleColor ProgressBackgroundColor { - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return _hostUserInterface.ProgressBackgroundColor; } - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { _hostUserInterface.ProgressBackgroundColor = value; } } diff --git a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs index a53aac17b..6742ef83e 100644 --- a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs @@ -691,56 +691,52 @@ private void WriteDebuggerBanner(DebuggerStopEventArgs eventArgs) /// /// /// - public static ConsoleColor BackgroundColor - { - get; - set; - } + internal static ConsoleColor BackgroundColor { get; set; } /// /// /// - public ConsoleColor ErrorForegroundColor { get; set; } = ConsoleColor.Red; + internal ConsoleColor ErrorForegroundColor { get; set; } = ConsoleColor.Red; /// /// /// - public ConsoleColor ErrorBackgroundColor { get; set; } = BackgroundColor; + internal ConsoleColor ErrorBackgroundColor { get; set; } = BackgroundColor; /// /// /// - public ConsoleColor WarningForegroundColor { get; set; } = ConsoleColor.Yellow; + internal ConsoleColor WarningForegroundColor { get; set; } = ConsoleColor.Yellow; /// /// /// - public ConsoleColor WarningBackgroundColor { get; set; } = BackgroundColor; + internal ConsoleColor WarningBackgroundColor { get; set; } = BackgroundColor; /// /// /// - public ConsoleColor DebugForegroundColor { get; set; } = ConsoleColor.Yellow; + internal ConsoleColor DebugForegroundColor { get; set; } = ConsoleColor.Yellow; /// /// /// - public ConsoleColor DebugBackgroundColor { get; set; } = BackgroundColor; + internal ConsoleColor DebugBackgroundColor { get; set; } = BackgroundColor; /// /// /// - public ConsoleColor VerboseForegroundColor { get; set; } = ConsoleColor.Yellow; + internal ConsoleColor VerboseForegroundColor { get; set; } = ConsoleColor.Yellow; /// /// /// - public ConsoleColor VerboseBackgroundColor { get; set; } = BackgroundColor; + internal ConsoleColor VerboseBackgroundColor { get; set; } = BackgroundColor; /// /// /// - public ConsoleColor ProgressForegroundColor { get; set; } = ConsoleColor.Yellow; + internal ConsoleColor ProgressForegroundColor { get; set; } = ConsoleColor.Yellow; /// /// /// - public ConsoleColor ProgressBackgroundColor { get; set; } = ConsoleColor.DarkCyan; + internal ConsoleColor ProgressBackgroundColor { get; set; } = ConsoleColor.DarkCyan; private async Task StartReplLoop(CancellationToken cancellationToken) { From d3007207246c7aace0de47a627edcd578d162375 Mon Sep 17 00:00:00 2001 From: GUIGHIL benjamin Date: Fri, 20 Apr 2018 15:16:39 +0200 Subject: [PATCH 3/4] Suppress Documentation for internal members Sorry I didn't notice that was only for public members until I read the error again. --- .../Session/Host/EditorServicesPSHost.cs | 6 ---- .../Host/EditorServicesPSHostUserInterface.cs | 33 ------------------- 2 files changed, 39 deletions(-) diff --git a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs index 89003ddba..3e99bcab5 100644 --- a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs +++ b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs @@ -77,16 +77,10 @@ public override string Name get { return this.hostDetails.Name; } } - /// - /// - /// internal class ConsoleColorProxy { private EditorServicesPSHostUserInterface _hostUserInterface; - /// - /// - /// internal ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface) { if (hostUserInterface == null) throw new ArgumentNullException("hostUserInterface"); diff --git a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs index 6742ef83e..2aceaaf10 100644 --- a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs @@ -688,54 +688,21 @@ private void WriteDebuggerBanner(DebuggerStopEventArgs eventArgs) } } - /// - /// - /// internal static ConsoleColor BackgroundColor { get; set; } - /// - /// - /// internal ConsoleColor ErrorForegroundColor { get; set; } = ConsoleColor.Red; - /// - /// - /// internal ConsoleColor ErrorBackgroundColor { get; set; } = BackgroundColor; - /// - /// - /// internal ConsoleColor WarningForegroundColor { get; set; } = ConsoleColor.Yellow; - /// - /// - /// internal ConsoleColor WarningBackgroundColor { get; set; } = BackgroundColor; - /// - /// - /// internal ConsoleColor DebugForegroundColor { get; set; } = ConsoleColor.Yellow; - /// - /// - /// internal ConsoleColor DebugBackgroundColor { get; set; } = BackgroundColor; - /// - /// - /// 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; private async Task StartReplLoop(CancellationToken cancellationToken) From ce13e6d66a639917d7cc5bdb406d072b775ba054 Mon Sep 17 00:00:00 2001 From: GUIGHIL benjamin Date: Fri, 20 Apr 2018 22:36:48 +0200 Subject: [PATCH 4/4] Add text for color sumary --- .../Session/Host/EditorServicesPSHost.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs index 3e99bcab5..33925f044 100644 --- a/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs +++ b/src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs @@ -88,7 +88,7 @@ internal ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface) } /// - /// + /// The ForegroundColor for Error /// public ConsoleColor ErrorForegroundColor { @@ -99,7 +99,7 @@ public ConsoleColor ErrorForegroundColor } /// - /// + /// The BackgroundColor for Error /// public ConsoleColor ErrorBackgroundColor { @@ -110,7 +110,7 @@ public ConsoleColor ErrorBackgroundColor } /// - /// + /// The ForegroundColor for Warning /// public ConsoleColor WarningForegroundColor { @@ -121,7 +121,7 @@ public ConsoleColor WarningForegroundColor } /// - /// + /// The BackgroundColor for Warning /// public ConsoleColor WarningBackgroundColor { @@ -132,7 +132,7 @@ public ConsoleColor WarningBackgroundColor } /// - /// + /// The ForegroundColor for Debug /// public ConsoleColor DebugForegroundColor { @@ -143,7 +143,7 @@ public ConsoleColor DebugForegroundColor } /// - /// + /// The BackgroundColor for Debug /// public ConsoleColor DebugBackgroundColor { @@ -154,7 +154,7 @@ public ConsoleColor DebugBackgroundColor } /// - /// + /// The ForegroundColor for Verbose /// public ConsoleColor VerboseForegroundColor { @@ -165,7 +165,7 @@ public ConsoleColor VerboseForegroundColor } /// - /// + /// The BackgroundColor for Verbose /// public ConsoleColor VerboseBackgroundColor { @@ -176,7 +176,7 @@ public ConsoleColor VerboseBackgroundColor } /// - /// + /// The ForegroundColor for Progress /// public ConsoleColor ProgressForegroundColor { @@ -187,7 +187,7 @@ public ConsoleColor ProgressForegroundColor } /// - /// + /// The BackgroundColor for Progress /// public ConsoleColor ProgressBackgroundColor {