Skip to content

Add customize output color enhancement #654

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
merged 4 commits into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ install:

script:
- ulimit -n 4096
- powershell -File scripts/travis.ps1
- powershell -File scripts/travis.ps1
160 changes: 156 additions & 4 deletions src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.PowerShell.EditorServices.Session;
using Microsoft.PowerShell.EditorServices.Utility;
using System;
using System.Diagnostics.CodeAnalysis;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed after the SuppressMessage attributes are removed.

using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;
Expand Down Expand Up @@ -78,14 +79,165 @@ public override string Name
}

/// <summary>
///
///
/// </summary>
public class ConsoleColorProxy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be internal class ConsoleColorProxy since the only intended way to access it is via the PSObject. The empty documentation comment can then be removed as well

Copy link
Contributor Author

@KeroroLulu KeroroLulu Apr 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SeeminglyScience Sorry I delete my comments in your review, afterwards I notice that the error I get with travis was from public members. I didn't notice that it work with internal members. And when I pushed that change AppVeyor worked I don't know why it was stuck for 20 minute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor and Travis sometimes have issues (not our issues) and it's just a matter of restarting the build and it works. 😀

{
private EditorServicesPSHostUserInterface _hostUserInterface;

/// <summary>
///
/// </summary>
public ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be internal ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface) , the empty documentation comment can then be removed as well

{
if (hostUserInterface == null) throw new ArgumentNullException("hostUserInterface");
_hostUserInterface = hostUserInterface;
}

/// <summary>
///
/// </summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you either remove these summaries or add like

"The ForegroundColor for Errors"
etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add text, I think that your configuration of travis doesn't accept warning from XML documentation for public members

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

public ConsoleColor ErrorForegroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the diagnostic suppressions (SuppressMessage) can be removed since we don't have the same analyzers on the project

get
{ return _hostUserInterface.ErrorForegroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.ErrorForegroundColor = value; }
}

/// <summary>
///
/// </summary>
public ConsoleColor ErrorBackgroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get
{ return _hostUserInterface.ErrorBackgroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.ErrorBackgroundColor = value; }
}

/// <summary>
///
/// </summary>
public ConsoleColor WarningForegroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get
{ return _hostUserInterface.WarningForegroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.WarningForegroundColor = value; }
}

/// <summary>
///
/// </summary>
public ConsoleColor WarningBackgroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get
{ return _hostUserInterface.WarningBackgroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.WarningBackgroundColor = value; }
}

/// <summary>
///
/// </summary>
public ConsoleColor DebugForegroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get
{ return _hostUserInterface.DebugForegroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.DebugForegroundColor = value; }
}

/// <summary>
///
/// </summary>
public ConsoleColor DebugBackgroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get
{ return _hostUserInterface.DebugBackgroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.DebugBackgroundColor = value; }
}

/// <summary>
///
/// </summary>
public ConsoleColor VerboseForegroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get
{ return _hostUserInterface.VerboseForegroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.VerboseForegroundColor = value; }
}

/// <summary>
///
/// </summary>
public ConsoleColor VerboseBackgroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get
{ return _hostUserInterface.VerboseBackgroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.VerboseBackgroundColor = value; }
}

/// <summary>
///
/// </summary>
public ConsoleColor ProgressForegroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get
{ return _hostUserInterface.ProgressForegroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.ProgressForegroundColor = value; }
}

/// <summary>
///
/// </summary>
public ConsoleColor ProgressBackgroundColor
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
get
{ return _hostUserInterface.ProgressBackgroundColor; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
set
{ _hostUserInterface.ProgressBackgroundColor = value; }
}
}

/// <summary>
/// Return the actual console host object so that the user can get at
/// the unproxied methods.
/// </summary>
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;

/// <summary>
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,8 @@ public override void WriteDebugLine(string message)
DebugMessagePrefix + message,
true,
OutputType.Debug,
foregroundColor: ConsoleColor.Yellow);
foregroundColor: this.DebugForegroundColor,
backgroundColor: this.DebugBackgroundColor);
}

/// <summary>
Expand All @@ -542,7 +543,8 @@ public override void WriteVerboseLine(string message)
VerboseMessagePrefix + message,
true,
OutputType.Verbose,
foregroundColor: ConsoleColor.Blue);
foregroundColor: this.VerboseForegroundColor,
backgroundColor: this.VerboseBackgroundColor);
}

/// <summary>
Expand All @@ -555,7 +557,8 @@ public override void WriteWarningLine(string message)
WarningMessagePrefix + message,
true,
OutputType.Warning,
foregroundColor: ConsoleColor.Yellow);
foregroundColor: this.WarningForegroundColor,
backgroundColor: this.WarningBackgroundColor);
}

/// <summary>
Expand All @@ -568,7 +571,8 @@ public override void WriteErrorLine(string value)
value,
true,
OutputType.Error,
ConsoleColor.Red);
foregroundColor: this.ErrorForegroundColor,
backgroundColor: this.ErrorBackgroundColor);
}

/// <summary>
Expand Down Expand Up @@ -684,6 +688,60 @@ private void WriteDebuggerBanner(DebuggerStopEventArgs eventArgs)
}
}

/// <summary>
///
/// </summary>
public static ConsoleColor BackgroundColor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the color properties here can be internal, the empty documentation comments can then be removed as well.

{
get;
set;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should follow the same style as below (e.g. public static ConsoleColor BackgroundColor { get; set; })


/// <summary>
///
/// </summary>
public ConsoleColor ErrorForegroundColor { get; set; } = ConsoleColor.Red;
/// <summary>
///
/// </summary>
public ConsoleColor ErrorBackgroundColor { get; set; } = BackgroundColor;

/// <summary>
///
/// </summary>
public ConsoleColor WarningForegroundColor { get; set; } = ConsoleColor.Yellow;
/// <summary>
///
/// </summary>
public ConsoleColor WarningBackgroundColor { get; set; } = BackgroundColor;

/// <summary>
///
/// </summary>
public ConsoleColor DebugForegroundColor { get; set; } = ConsoleColor.Yellow;
/// <summary>
///
/// </summary>
public ConsoleColor DebugBackgroundColor { get; set; } = BackgroundColor;

/// <summary>
///
/// </summary>
public ConsoleColor VerboseForegroundColor { get; set; } = ConsoleColor.Yellow;
/// <summary>
///
/// </summary>
public ConsoleColor VerboseBackgroundColor { get; set; } = BackgroundColor;

/// <summary>
///
/// </summary>
public ConsoleColor ProgressForegroundColor { get; set; } = ConsoleColor.Yellow;
/// <summary>
///
/// </summary>
public ConsoleColor ProgressBackgroundColor { get; set; } = ConsoleColor.DarkCyan;

private async Task StartReplLoop(CancellationToken cancellationToken)
{
do
Expand Down