PS> Install-Package Colors.Netusing Colors.Net;
ColoredConsole.WriteLine("Hello, World");
ColoredConsole.Write("Hello, World");So it's pretty much the same surface as System.Console. However, to add color, all you have to do is either
using Colors.Net.StringColorExtensions;
ColoredConsole.WriteLine($"{"Hello".Red()}, world!");or
using static Colors.Net.StringStaticMethods;
ColoredConsole.WriteLine($"{Red("Hello")}, World");Since this is just manipulating strings, it's very easy to use which ever pattern you like. I personally like:
using Colors.Net.StringColorExtensions;
var @hello = "Hello".Red();
ColoredConsole.WriteLine($"{@hello}, World");and the result of course is the same in all 2 cases:
You can also use nested colors and they will work as you'd expect string concat to work. For example:
var @yellow = Yellow("I'm Yellow!");
var @red = Red("I'm Red!");
var @blue = "I'm Blue".Blue(); // just to show a different way
ColoredConsole
.WriteLine($@"{Green($"I'm green yet {@yellow}, {@red}, {@blue} and back to green.")}");and this prints:
I like chaining calls that logically make sense together. Anyway, WriteLine() and Write() return an instance of IConsoleWriter so you can chain WriteLine() and Write() calls. It looks something like this:
ColoredConsole
.WriteLine($"{DarkCyan("Title:")} Welcome to My Cli")
.WriteLine()
.WriteLine($"{DarkCyan("Version:")} {Magenta("1.0.0")}");and that prints:
ColoredConsole
.WriteLine($@"{Green($"I'm green yet {@yellow}, {@red}, {@blue} and back to green.")}");Has 0.1 msec overhead when compared to Console.WriteLine(). This is measured by the Runner project doing this 10,000 with an extra runtime of 1000 msec.
The interface is inspired by colors.js.
All colors in System.ConsoleColor enum.


