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 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
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
133 changes: 129 additions & 4 deletions src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,140 @@ 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");
_hostUserInterface = hostUserInterface;
}

/// <summary>
/// The ForegroundColor for Error
/// </summary>
public ConsoleColor ErrorForegroundColor
{
get
{ return _hostUserInterface.ErrorForegroundColor; }
set
{ _hostUserInterface.ErrorForegroundColor = value; }
}

/// <summary>
/// The BackgroundColor for Error
/// </summary>
public ConsoleColor ErrorBackgroundColor
{
get
{ return _hostUserInterface.ErrorBackgroundColor; }
set
{ _hostUserInterface.ErrorBackgroundColor = value; }
}

/// <summary>
/// The ForegroundColor for Warning
/// </summary>
public ConsoleColor WarningForegroundColor
{
get
{ return _hostUserInterface.WarningForegroundColor; }
set
{ _hostUserInterface.WarningForegroundColor = value; }
}

/// <summary>
/// The BackgroundColor for Warning
/// </summary>
public ConsoleColor WarningBackgroundColor
{
get
{ return _hostUserInterface.WarningBackgroundColor; }
set
{ _hostUserInterface.WarningBackgroundColor = value; }
}

/// <summary>
/// The ForegroundColor for Debug
/// </summary>
public ConsoleColor DebugForegroundColor
{
get
{ return _hostUserInterface.DebugForegroundColor; }
set
{ _hostUserInterface.DebugForegroundColor = value; }
}

/// <summary>
/// The BackgroundColor for Debug
/// </summary>
public ConsoleColor DebugBackgroundColor
{
get
{ return _hostUserInterface.DebugBackgroundColor; }
set
{ _hostUserInterface.DebugBackgroundColor = value; }
}

/// <summary>
/// The ForegroundColor for Verbose
/// </summary>
public ConsoleColor VerboseForegroundColor
{
get
{ return _hostUserInterface.VerboseForegroundColor; }
set
{ _hostUserInterface.VerboseForegroundColor = value; }
}

/// <summary>
/// The BackgroundColor for Verbose
/// </summary>
public ConsoleColor VerboseBackgroundColor
{
get
{ return _hostUserInterface.VerboseBackgroundColor; }
set
{ _hostUserInterface.VerboseBackgroundColor = value; }
}

/// <summary>
/// The ForegroundColor for Progress
/// </summary>
public ConsoleColor ProgressForegroundColor
{
get
{ return _hostUserInterface.ProgressForegroundColor; }
set
{ _hostUserInterface.ProgressForegroundColor = value; }
}

/// <summary>
/// The BackgroundColor for Progress
/// </summary>
public ConsoleColor ProgressBackgroundColor
{
get
{ return _hostUserInterface.ProgressBackgroundColor; }
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,23 @@ 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)
{
do
Expand Down