Skip to content

Commit e37f1f2

Browse files
KeroroLuluTylerLeonhardt
authored andcommitted
Add customize output color enhancement (#654)
* 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 * 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. * Suppress Documentation for internal members Sorry I didn't notice that was only for public members until I read the error again. * Add text for color sumary
1 parent 4716b7f commit e37f1f2

File tree

3 files changed

+155
-9
lines changed

3 files changed

+155
-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

+129-4
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,140 @@ public override string Name
7777
get { return this.hostDetails.Name; }
7878
}
7979

80+
internal class ConsoleColorProxy
81+
{
82+
private EditorServicesPSHostUserInterface _hostUserInterface;
83+
84+
internal ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface)
85+
{
86+
if (hostUserInterface == null) throw new ArgumentNullException("hostUserInterface");
87+
_hostUserInterface = hostUserInterface;
88+
}
89+
90+
/// <summary>
91+
/// The ForegroundColor for Error
92+
/// </summary>
93+
public ConsoleColor ErrorForegroundColor
94+
{
95+
get
96+
{ return _hostUserInterface.ErrorForegroundColor; }
97+
set
98+
{ _hostUserInterface.ErrorForegroundColor = value; }
99+
}
100+
101+
/// <summary>
102+
/// The BackgroundColor for Error
103+
/// </summary>
104+
public ConsoleColor ErrorBackgroundColor
105+
{
106+
get
107+
{ return _hostUserInterface.ErrorBackgroundColor; }
108+
set
109+
{ _hostUserInterface.ErrorBackgroundColor = value; }
110+
}
111+
112+
/// <summary>
113+
/// The ForegroundColor for Warning
114+
/// </summary>
115+
public ConsoleColor WarningForegroundColor
116+
{
117+
get
118+
{ return _hostUserInterface.WarningForegroundColor; }
119+
set
120+
{ _hostUserInterface.WarningForegroundColor = value; }
121+
}
122+
123+
/// <summary>
124+
/// The BackgroundColor for Warning
125+
/// </summary>
126+
public ConsoleColor WarningBackgroundColor
127+
{
128+
get
129+
{ return _hostUserInterface.WarningBackgroundColor; }
130+
set
131+
{ _hostUserInterface.WarningBackgroundColor = value; }
132+
}
133+
134+
/// <summary>
135+
/// The ForegroundColor for Debug
136+
/// </summary>
137+
public ConsoleColor DebugForegroundColor
138+
{
139+
get
140+
{ return _hostUserInterface.DebugForegroundColor; }
141+
set
142+
{ _hostUserInterface.DebugForegroundColor = value; }
143+
}
144+
145+
/// <summary>
146+
/// The BackgroundColor for Debug
147+
/// </summary>
148+
public ConsoleColor DebugBackgroundColor
149+
{
150+
get
151+
{ return _hostUserInterface.DebugBackgroundColor; }
152+
set
153+
{ _hostUserInterface.DebugBackgroundColor = value; }
154+
}
155+
156+
/// <summary>
157+
/// The ForegroundColor for Verbose
158+
/// </summary>
159+
public ConsoleColor VerboseForegroundColor
160+
{
161+
get
162+
{ return _hostUserInterface.VerboseForegroundColor; }
163+
set
164+
{ _hostUserInterface.VerboseForegroundColor = value; }
165+
}
166+
167+
/// <summary>
168+
/// The BackgroundColor for Verbose
169+
/// </summary>
170+
public ConsoleColor VerboseBackgroundColor
171+
{
172+
get
173+
{ return _hostUserInterface.VerboseBackgroundColor; }
174+
set
175+
{ _hostUserInterface.VerboseBackgroundColor = value; }
176+
}
177+
178+
/// <summary>
179+
/// The ForegroundColor for Progress
180+
/// </summary>
181+
public ConsoleColor ProgressForegroundColor
182+
{
183+
get
184+
{ return _hostUserInterface.ProgressForegroundColor; }
185+
set
186+
{ _hostUserInterface.ProgressForegroundColor = value; }
187+
}
188+
189+
/// <summary>
190+
/// The BackgroundColor for Progress
191+
/// </summary>
192+
public ConsoleColor ProgressBackgroundColor
193+
{
194+
get
195+
{ return _hostUserInterface.ProgressBackgroundColor; }
196+
set
197+
{ _hostUserInterface.ProgressBackgroundColor = value; }
198+
}
199+
}
200+
80201
/// <summary>
81-
///
202+
/// Return the actual console host object so that the user can get at
203+
/// the unproxied methods.
82204
/// </summary>
83205
public override PSObject PrivateData
84206
{
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(); }
207+
get
208+
{
209+
if (hostUserInterface == null) return null;
210+
return _consoleColorProxy ?? (_consoleColorProxy = PSObject.AsPSObject(new ConsoleColorProxy(hostUserInterface)));
211+
}
88212
}
213+
private PSObject _consoleColorProxy;
89214

90215
/// <summary>
91216
///

src/PowerShellEditorServices/Session/Host/EditorServicesPSHostUserInterface.cs

+25-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,23 @@ private void WriteDebuggerBanner(DebuggerStopEventArgs eventArgs)
684688
}
685689
}
686690

691+
internal static ConsoleColor BackgroundColor { get; set; }
692+
693+
internal ConsoleColor ErrorForegroundColor { get; set; } = ConsoleColor.Red;
694+
internal ConsoleColor ErrorBackgroundColor { get; set; } = BackgroundColor;
695+
696+
internal ConsoleColor WarningForegroundColor { get; set; } = ConsoleColor.Yellow;
697+
internal ConsoleColor WarningBackgroundColor { get; set; } = BackgroundColor;
698+
699+
internal ConsoleColor DebugForegroundColor { get; set; } = ConsoleColor.Yellow;
700+
internal ConsoleColor DebugBackgroundColor { get; set; } = BackgroundColor;
701+
702+
internal ConsoleColor VerboseForegroundColor { get; set; } = ConsoleColor.Yellow;
703+
internal ConsoleColor VerboseBackgroundColor { get; set; } = BackgroundColor;
704+
705+
internal ConsoleColor ProgressForegroundColor { get; set; } = ConsoleColor.Yellow;
706+
internal ConsoleColor ProgressBackgroundColor { get; set; } = ConsoleColor.DarkCyan;
707+
687708
private async Task StartReplLoop(CancellationToken cancellationToken)
688709
{
689710
do

0 commit comments

Comments
 (0)