Skip to content

Commit e2a32aa

Browse files
author
GUIGHIL benjamin
committed
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
1 parent 4716b7f commit e2a32aa

File tree

3 files changed

+219
-9
lines changed

3 files changed

+219
-9
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ install:
2626

2727
script:
2828
- ulimit -n 4096
29-
- powershell -File scripts/travis.ps1
29+
- powershell -File scripts/travis.ps1

src/PowerShellEditorServices/Session/Host/EditorServicesPSHost.cs

+156-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.PowerShell.EditorServices.Session;
77
using Microsoft.PowerShell.EditorServices.Utility;
88
using System;
9+
using System.Diagnostics.CodeAnalysis;
910
using System.Management.Automation;
1011
using System.Management.Automation.Host;
1112
using System.Management.Automation.Runspaces;
@@ -78,14 +79,165 @@ public override string Name
7879
}
7980

8081
/// <summary>
81-
///
82+
///
83+
/// </summary>
84+
public class ConsoleColorProxy
85+
{
86+
private EditorServicesPSHostUserInterface _hostUserInterface;
87+
88+
/// <summary>
89+
///
90+
/// </summary>
91+
public ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface)
92+
{
93+
if (hostUserInterface == null) throw new ArgumentNullException("hostUserInterface");
94+
_hostUserInterface = hostUserInterface;
95+
}
96+
97+
/// <summary>
98+
///
99+
/// </summary>
100+
public ConsoleColor ErrorForegroundColor
101+
{
102+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
103+
get
104+
{ return _hostUserInterface.ErrorForegroundColor; }
105+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
106+
set
107+
{ _hostUserInterface.ErrorForegroundColor = value; }
108+
}
109+
110+
/// <summary>
111+
///
112+
/// </summary>
113+
public ConsoleColor ErrorBackgroundColor
114+
{
115+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
116+
get
117+
{ return _hostUserInterface.ErrorBackgroundColor; }
118+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
119+
set
120+
{ _hostUserInterface.ErrorBackgroundColor = value; }
121+
}
122+
123+
/// <summary>
124+
///
125+
/// </summary>
126+
public ConsoleColor WarningForegroundColor
127+
{
128+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
129+
get
130+
{ return _hostUserInterface.WarningForegroundColor; }
131+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
132+
set
133+
{ _hostUserInterface.WarningForegroundColor = value; }
134+
}
135+
136+
/// <summary>
137+
///
138+
/// </summary>
139+
public ConsoleColor WarningBackgroundColor
140+
{
141+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
142+
get
143+
{ return _hostUserInterface.WarningBackgroundColor; }
144+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
145+
set
146+
{ _hostUserInterface.WarningBackgroundColor = value; }
147+
}
148+
149+
/// <summary>
150+
///
151+
/// </summary>
152+
public ConsoleColor DebugForegroundColor
153+
{
154+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
155+
get
156+
{ return _hostUserInterface.DebugForegroundColor; }
157+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
158+
set
159+
{ _hostUserInterface.DebugForegroundColor = value; }
160+
}
161+
162+
/// <summary>
163+
///
164+
/// </summary>
165+
public ConsoleColor DebugBackgroundColor
166+
{
167+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
168+
get
169+
{ return _hostUserInterface.DebugBackgroundColor; }
170+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
171+
set
172+
{ _hostUserInterface.DebugBackgroundColor = value; }
173+
}
174+
175+
/// <summary>
176+
///
177+
/// </summary>
178+
public ConsoleColor VerboseForegroundColor
179+
{
180+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
181+
get
182+
{ return _hostUserInterface.VerboseForegroundColor; }
183+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
184+
set
185+
{ _hostUserInterface.VerboseForegroundColor = value; }
186+
}
187+
188+
/// <summary>
189+
///
190+
/// </summary>
191+
public ConsoleColor VerboseBackgroundColor
192+
{
193+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
194+
get
195+
{ return _hostUserInterface.VerboseBackgroundColor; }
196+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
197+
set
198+
{ _hostUserInterface.VerboseBackgroundColor = value; }
199+
}
200+
201+
/// <summary>
202+
///
203+
/// </summary>
204+
public ConsoleColor ProgressForegroundColor
205+
{
206+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
207+
get
208+
{ return _hostUserInterface.ProgressForegroundColor; }
209+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
210+
set
211+
{ _hostUserInterface.ProgressForegroundColor = value; }
212+
}
213+
214+
/// <summary>
215+
///
216+
/// </summary>
217+
public ConsoleColor ProgressBackgroundColor
218+
{
219+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
220+
get
221+
{ return _hostUserInterface.ProgressBackgroundColor; }
222+
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
223+
set
224+
{ _hostUserInterface.ProgressBackgroundColor = value; }
225+
}
226+
}
227+
228+
/// <summary>
229+
/// Return the actual console host object so that the user can get at
230+
/// the unproxied methods.
82231
/// </summary>
83232
public override PSObject PrivateData
84233
{
85-
// There is no PrivateData yet but by returning an empty object we can get past PowerShell's
86-
// check for $host.PrivateData["window"] which errors on the null returned by default.
87-
get { return new PSObject(); }
234+
get
235+
{
236+
if (hostUserInterface == null) return null;
237+
return _consoleColorProxy ?? (_consoleColorProxy = PSObject.AsPSObject(new ConsoleColorProxy(hostUserInterface)));
238+
}
88239
}
240+
private PSObject _consoleColorProxy;
89241

90242
/// <summary>
91243
///

src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs

+62-4
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@ public override void WriteDebugLine(string message)
529529
DebugMessagePrefix + message,
530530
true,
531531
OutputType.Debug,
532-
foregroundColor: ConsoleColor.Yellow);
532+
foregroundColor: this.DebugForegroundColor,
533+
backgroundColor: this.DebugBackgroundColor);
533534
}
534535

535536
/// <summary>
@@ -542,7 +543,8 @@ public override void WriteVerboseLine(string message)
542543
VerboseMessagePrefix + message,
543544
true,
544545
OutputType.Verbose,
545-
foregroundColor: ConsoleColor.Blue);
546+
foregroundColor: this.VerboseForegroundColor,
547+
backgroundColor: this.VerboseBackgroundColor);
546548
}
547549

548550
/// <summary>
@@ -555,7 +557,8 @@ public override void WriteWarningLine(string message)
555557
WarningMessagePrefix + message,
556558
true,
557559
OutputType.Warning,
558-
foregroundColor: ConsoleColor.Yellow);
560+
foregroundColor: this.WarningForegroundColor,
561+
backgroundColor: this.WarningBackgroundColor);
559562
}
560563

561564
/// <summary>
@@ -568,7 +571,8 @@ public override void WriteErrorLine(string value)
568571
value,
569572
true,
570573
OutputType.Error,
571-
ConsoleColor.Red);
574+
foregroundColor: this.ErrorForegroundColor,
575+
backgroundColor: this.ErrorBackgroundColor);
572576
}
573577

574578
/// <summary>
@@ -684,6 +688,60 @@ private void WriteDebuggerBanner(DebuggerStopEventArgs eventArgs)
684688
}
685689
}
686690

691+
/// <summary>
692+
///
693+
/// </summary>
694+
public static ConsoleColor BackgroundColor
695+
{
696+
get;
697+
set;
698+
}
699+
700+
/// <summary>
701+
///
702+
/// </summary>
703+
public ConsoleColor ErrorForegroundColor { get; set; } = ConsoleColor.Red;
704+
/// <summary>
705+
///
706+
/// </summary>
707+
public ConsoleColor ErrorBackgroundColor { get; set; } = BackgroundColor;
708+
709+
/// <summary>
710+
///
711+
/// </summary>
712+
public ConsoleColor WarningForegroundColor { get; set; } = ConsoleColor.Yellow;
713+
/// <summary>
714+
///
715+
/// </summary>
716+
public ConsoleColor WarningBackgroundColor { get; set; } = BackgroundColor;
717+
718+
/// <summary>
719+
///
720+
/// </summary>
721+
public ConsoleColor DebugForegroundColor { get; set; } = ConsoleColor.Yellow;
722+
/// <summary>
723+
///
724+
/// </summary>
725+
public ConsoleColor DebugBackgroundColor { get; set; } = BackgroundColor;
726+
727+
/// <summary>
728+
///
729+
/// </summary>
730+
public ConsoleColor VerboseForegroundColor { get; set; } = ConsoleColor.Yellow;
731+
/// <summary>
732+
///
733+
/// </summary>
734+
public ConsoleColor VerboseBackgroundColor { get; set; } = BackgroundColor;
735+
736+
/// <summary>
737+
///
738+
/// </summary>
739+
public ConsoleColor ProgressForegroundColor { get; set; } = ConsoleColor.Yellow;
740+
/// <summary>
741+
///
742+
/// </summary>
743+
public ConsoleColor ProgressBackgroundColor { get; set; } = ConsoleColor.DarkCyan;
744+
687745
private async Task StartReplLoop(CancellationToken cancellationToken)
688746
{
689747
do

0 commit comments

Comments
 (0)