update with @stephentoub 's suggested changes

This commit is contained in:
Bryan 2016-02-24 10:51:36 -08:00
parent b2fab6df02
commit a986a89dcc
2 changed files with 38 additions and 17 deletions

View file

@ -11,6 +11,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
private AnsiConsole(TextWriter writer)
{
Writer = writer;
OriginalForegroundColor = Console.ForegroundColor;
}
@ -32,7 +33,13 @@ namespace Microsoft.DotNet.Cli.Build.Framework
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)
@ -43,10 +50,18 @@ namespace Microsoft.DotNet.Cli.Build.Framework
return;
}
Console.ForegroundColor = (ConsoleColor)((int)Console.ForegroundColor ^ 0x08);
// switches on _boldRecursion to handle boldness
SetColor(Console.ForegroundColor);
}
public void WriteLine(string message)
{
Write(message);
Writer.WriteLine();
}
public void Write(string message)
{
var escapeScan = 0;
for (;;)
@ -125,7 +140,6 @@ namespace Microsoft.DotNet.Cli.Build.Framework
escapeScan = endIndex + 1;
}
}
Writer.WriteLine();
}
}
}

View file

@ -33,7 +33,13 @@ namespace Microsoft.DotNet.Cli.Utils
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)
@ -44,7 +50,8 @@ namespace Microsoft.DotNet.Cli.Utils
return;
}
Console.ForegroundColor = (ConsoleColor)((int)Console.ForegroundColor ^ 0x08);
// switches on _boldRecursion to handle boldness
SetColor(Console.ForegroundColor);
}
public void WriteLine(string message)