update with @stephentoub 's suggested changes
This commit is contained in:
parent
b2fab6df02
commit
a986a89dcc
2 changed files with 38 additions and 17 deletions
|
@ -11,6 +11,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
||||||
private AnsiConsole(TextWriter writer)
|
private AnsiConsole(TextWriter writer)
|
||||||
{
|
{
|
||||||
Writer = writer;
|
Writer = writer;
|
||||||
|
|
||||||
OriginalForegroundColor = Console.ForegroundColor;
|
OriginalForegroundColor = Console.ForegroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +33,13 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
||||||
|
|
||||||
private void SetColor(ConsoleColor color)
|
private void SetColor(ConsoleColor color)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = (ConsoleColor)(((int)Console.ForegroundColor & 0x08) | ((int)color & 0x07));
|
const int Light = 0x08;
|
||||||
|
int c = (int)color;
|
||||||
|
|
||||||
|
Console.ForegroundColor =
|
||||||
|
c < 0 ? color : // unknown, just use it
|
||||||
|
_boldRecursion > 0 ? (ConsoleColor)(c & ~Light) : // ensure color is dark
|
||||||
|
(ConsoleColor)(c | Light); // ensure color is light
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetBold(bool bold)
|
private void SetBold(bool bold)
|
||||||
|
@ -43,10 +50,18 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.ForegroundColor = (ConsoleColor)((int)Console.ForegroundColor ^ 0x08);
|
// switches on _boldRecursion to handle boldness
|
||||||
|
SetColor(Console.ForegroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteLine(string message)
|
public void WriteLine(string message)
|
||||||
|
{
|
||||||
|
Write(message);
|
||||||
|
Writer.WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Write(string message)
|
||||||
{
|
{
|
||||||
var escapeScan = 0;
|
var escapeScan = 0;
|
||||||
for (;;)
|
for (;;)
|
||||||
|
@ -125,7 +140,6 @@ namespace Microsoft.DotNet.Cli.Build.Framework
|
||||||
escapeScan = endIndex + 1;
|
escapeScan = endIndex + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Writer.WriteLine();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,13 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
|
|
||||||
private void SetColor(ConsoleColor color)
|
private void SetColor(ConsoleColor color)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = (ConsoleColor)(((int)Console.ForegroundColor & 0x08) | ((int)color & 0x07));
|
const int Light = 0x08;
|
||||||
|
int c = (int)color;
|
||||||
|
|
||||||
|
Console.ForegroundColor =
|
||||||
|
c < 0 ? color : // unknown, just use it
|
||||||
|
_boldRecursion > 0 ? (ConsoleColor)(c & ~Light) : // ensure color is dark
|
||||||
|
(ConsoleColor)(c | Light); // ensure color is light
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetBold(bool bold)
|
private void SetBold(bool bold)
|
||||||
|
@ -44,7 +50,8 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.ForegroundColor = (ConsoleColor)((int)Console.ForegroundColor ^ 0x08);
|
// switches on _boldRecursion to handle boldness
|
||||||
|
SetColor(Console.ForegroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteLine(string message)
|
public void WriteLine(string message)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue