Skip to content

Fix #387: Add foreground colors and prefixes to Write-* command output #388

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 2 commits into from
Mar 16, 2017
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
1 change: 1 addition & 0 deletions src/PowerShellEditorServices/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Microsoft.PowerShell.EditorServices.Test")]
[assembly: InternalsVisibleTo("Microsoft.PowerShell.EditorServices.Test.Shared")]

29 changes: 20 additions & 9 deletions src/PowerShellEditorServices/Session/SessionPSHostUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ internal class ConsoleServicePSHostUserInterface : PSHostUserInterface, IHostUIS

#endregion

#region Public Constants

public const string DebugMessagePrefix = "DEBUG: ";
public const string WarningMessagePrefix = "WARNING: ";
public const string VerboseMessagePrefix = "VERBOSE: ";

#endregion

#region Properties

internal IConsoleHost ConsoleHost
Expand Down Expand Up @@ -57,9 +65,9 @@ public ConsoleServicePSHostUserInterface(bool enableConsoleRepl)
{
if (enableConsoleRepl)
{
// Set the output encoding to Unicode so that all
// Unicode characters are written correctly
System.Console.OutputEncoding = System.Text.Encoding.Unicode;
// Set the output encoding to UTF-8 so that special
// characters are written to the console correctly
System.Console.OutputEncoding = System.Text.Encoding.UTF8;
}

this.rawUserInterface =
Expand Down Expand Up @@ -338,9 +346,10 @@ public override void WriteDebugLine(string message)
if (this.consoleHost != null)
{
this.consoleHost.WriteOutput(
message,
DebugMessagePrefix + message,
true,
OutputType.Debug);
OutputType.Debug,
foregroundColor: ConsoleColor.Yellow);
}
}

Expand All @@ -349,9 +358,10 @@ public override void WriteVerboseLine(string message)
if (this.consoleHost != null)
{
this.consoleHost.WriteOutput(
message,
VerboseMessagePrefix + message,
true,
OutputType.Verbose);
OutputType.Verbose,
foregroundColor: ConsoleColor.Blue);
}
}

Expand All @@ -360,9 +370,10 @@ public override void WriteWarningLine(string message)
if (this.consoleHost != null)
{
this.consoleHost.WriteOutput(
message,
WarningMessagePrefix + message,
true,
OutputType.Warning);
OutputType.Warning,
foregroundColor: ConsoleColor.Yellow);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ await this.powerShellContext.ExecuteScriptString(
TestOutputString));

Assert.Equal(
TestOutputString + Environment.NewLine,
ConsoleServicePSHostUserInterface.VerboseMessagePrefix + TestOutputString + Environment.NewLine,
this.GetOutputForType(OutputType.Verbose));
}

Expand All @@ -137,7 +137,7 @@ await this.powerShellContext.ExecuteScriptString(
TestOutputString));

Assert.Equal(
TestOutputString + Environment.NewLine,
ConsoleServicePSHostUserInterface.DebugMessagePrefix + TestOutputString + Environment.NewLine,
this.GetOutputForType(OutputType.Debug));
}

Expand All @@ -150,7 +150,7 @@ await this.powerShellContext.ExecuteScriptString(
TestOutputString));

Assert.Equal(
TestOutputString + Environment.NewLine,
ConsoleServicePSHostUserInterface.WarningMessagePrefix + TestOutputString + Environment.NewLine,
this.GetOutputForType(OutputType.Warning));
}

Expand Down